我正在使用NEST在我的elasticsearch索引中搜索Event
对象。在基本级别上,Event
看起来像这样:
public class Event
{
public int Id {get; set;}
[ElasticProperty(Index = FieldIndexOption.NotAnalyzed)]
public string EventType {get; set;}
}
我的搜索如下所示:
SearchDescriptor<Event> search = new SearchDescriptor<Event>()
.From(0)
.Take(10000)
.QueryRaw(@"{""match_all"": {} }")
.FacetTerm("my_facet", f => f.OnField("eventType"));
var esResults = esClient.Search<Event>(search);
当前,我在ES中的所有文档的
eventType
都为Test type
,但是构面正在返回Test
和type
的结果,而不是将它们一起返回。我的理解是
Index = FieldIndexOption.NotAnalyzed
应该可以缓解此问题,但我仍然看到它。为什么会这样呢?
最佳答案
您确定索引是使用正确的映射创建的吗?
这段代码
var indicesOperationResponse = client.CreateIndex(descriptor => descriptor
.Index(indexName)
.AddMapping<Event>(m => m
.MapFromAttributes()));
使用以下映射创建索引
{
"my_index" : {
"mappings" : {
"event" : {
"properties" : {
"eventType" : {
"type" : "string",
"index" : "not_analyzed"
},
"id" : {
"type" : "integer"
}
}
}
}
}
}
您的查询工作正常,并返回正确的方面:
{
"took": 1,
"timed_out": false,
"_shards": {..},
"hits": {..},
"facets": {
"my_facet": {
"_type": "terms",
"missing": 0,
"total": 3,
"other": 0,
"terms": [
{
"term": "Test type",
"count": 3
}
]
}
}
}
我已经对Elasticsearch和NEST 1.5.0进行了测试。
关于c# - 即使在映射中定义了NotAnalyzed的属性,Elasticsearch NEST方面也将标记化字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30853469/