我使用包含另一个嵌套字段的嵌套字段索引Elasticsearch文档(因此字段为2步骤树)。我想根据内部嵌套字段中的数据来匹配文档,该字段无效。
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"}
}
}
我使用的是错误吗?
答案 0 :(得分:3)
根据你的映射event_attribute_value
进行分析。这意味着在索引短语期间,“奥巴马总统”被分析为两个标记:“总统”和“奥巴马”。您正在搜索索引中不存在的令牌“总统”和“奥巴马”。
您可以通过
解决此问题not_analyzed
,