【问题标题】:Elasticsearch NEST facet is tokenizing field even if attribute of NotAnalyzed is defined in the mapping即使在映射中定义了 NotAnalyzed 的属性,Elasticsearch NEST facet 也会标记字段
【发布时间】:2015-06-16 04:06:28
【问题描述】:

我正在使用 NEST 在我的弹性搜索索引中搜索 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 中的所有文档都有一个 eventTypeTest type,但方面正在返回 Testtype 的结果,而不是一起返回它们。

我的理解是 Index = FieldIndexOption.NotAnalyzed 应该可以缓解这个问题,但我仍然看到它。为什么会这样?

【问题讨论】:

    标签: c# elasticsearch nest


    【解决方案1】:

    您确定您的索引是使用正确的映射创建的吗?

    这段代码

    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 对其进行了测试。

    【讨论】:

    • 我在任何时候都没有明确地调用CreateIndex。该映射是否需要在创建索引时就位?
    • 您可以利用put mapping api。取决于您的用例,发布更多详细信息,所以也许我可以更聪明地讲述一些事情。
    • 我有一个简单的原型,用于在以前使用 Solr 的产品中测试 ES。我使用ElasticClient.IndexMany() 进行索引,然后按照我的问题中的描述进行搜索。
    • @Jim 和 ElasticProperty 在您的情况下被忽略。因此,elasticsearch 使用默认设置您的字段创建了映射。
    • 为什么ElasticProperty会被忽略?这让我很惊讶
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-01
    • 2020-03-30
    相关资源
    最近更新 更多