【问题标题】:ElasticSearch query with Nested filter is not working使用嵌套过滤器的 ElasticSearch 查询不起作用
【发布时间】:2015-06-07 09:36:26
【问题描述】:

我正在使用包含另一个嵌套字段的嵌套字段(因此一个字段的 2 步树)为 Elasticsearch 文档编制索引。我想根据内部嵌套字段中的数据匹配文档,这不起作用。

NestedFilterBuilder 如下所示..

        "nested" : {
          "filter" : {
            "or" : {
              "filters" : [ {
                "term" : {
                  "event_attribute_value" : "Obama"
                }
              }, {
                "term" : {
                  "event_attribute_value" : "President"
                }
              } ]
            }
          },
          "path" : "eventnested.attributes"
        }

这是我用来生成查询的 Java

orFilter.add(termFilter("event_attribute_value","president"));
NestedFilterBuilder nestedFilterBuilder = new NestedFilterBuilder("eventnested.attributes", orFilter);
finalFilter.add(nestedFilterBuilder);

建立索引的映射

"eventnested":{
            "type" : "nested", "store" : "yes", "index" : "analyzed", "omit_norms" : "true",
            "include_in_parent":true,
            "properties":{              
                "event_type":{"type" : "string", "store" : "yes", "index" : "analyzed","omit_norms" : "true"},
                "attributes":{
                "type" : "nested", "store" : "yes", "index" : "analyzed", "omit_norms" : "true",
                "include_in_parent":true,
                    "properties":{
                        "event_attribute_name":{"type" : "string", "store" : "yes", "index" : "analyzed","omit_norms" : "true"},
                        "event_attribute_value":{"type" : "string", "store" : "yes", "index" : "analyzed","omit_norms" : "true"}
                    }
                    },
                "event_attribute_instance":{"type" : "integer", "store" : "yes", "precision_step" : "0"}
                }                                           
                }

是不是我用错了什么?

【问题讨论】:

    标签: elasticsearch nested


    【解决方案1】:

    根据您的映射event_attribute_value 进行分析。这意味着在索引短语“President Obama”期间被分析为两个标记:“president”和“obama”。您正在搜索索引中不存在的标记“总统”和“奥巴马”。

    你可以解决这个问题

    1. 将字段映射更改为not_analyzed
    2. 用文本查询替换词条过滤器或
    3. 在您的术语过滤器中使用正确的标记(“president”和“obama”在 本例)。

    【讨论】:

    • 感谢您的工作。我使用 queryfilterbuilder 制作了 not_analyzed 字段。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-05
    • 2022-01-22
    • 2015-09-09
    • 1970-01-01
    • 1970-01-01
    • 2018-05-10
    • 2014-06-16
    相关资源
    最近更新 更多