https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html
问题描述:
对list中为dict类型的如何搜索
es 结构如下
PUT my_index/_doc/1 { "group" : "fans", "user" : [{ "first" : "John", "last" : "Smith" }, { "first" : "Alice", "last" : "White" } ] }
如何搜索 user不为空的 内容 ,使用
-d'
{
"query": {
"bool":{
"must_not" : {
"exists" : { "field" : "user" }
}
}
}
}'
可结果是空
解答:
GET my_index/_search { "query": { "nested": { "path": "user", "query": { "bool": { "must": [ { "exits": { "field": "user.first" }} ] } } } } }
过程分析:
1.Arrays of inner
object fields do not work the way you may expect. Lucene has no concept of inner objects, so Elasticsearch flattens object hierarchies into a simple list of field names and values. 【popexizhi: 对object fields 和 inner objects 的理解, 这里是因为 Lucense 无法对 内嵌的 object 直接搜索,所以有了我上面的结果】
2.
"nested": { "path": "user",
对 并列的 query 中字段名称的影响。这里是下面field 的引用根,指定路径时要加这个根
没有评论:
发表评论