I need to query on multiple nested fields on boolean types.Structure of mapping: "mappings" : { "properties" : { "leaders" : { "type" : "nested", "properties" : { "except_1" : { "type" : "boolean" }, "except_2" : { "type" : "boolean" }, "counter" : { "type" : "integer" } } } } }I am trying to use query both except1 and except2 only to False.Below my try, unfortunately it returns True and False for both fields and I cannot fix it. "query": { "nested": { "path": "leaders", "query": { "bool": { "must": [ { "term": { "leaders.except_1": False } }, { "term": { "leaders.except_2": False } } ] } } } } 解决方案 What you're probably looking for is the inner_hits option -- showing only the matched nested subdocuments.PUT leaders{"mappings":{"properties":{"leaders":{"type":"nested","properties":{"except_1":{"type":"boolean"},"except_2":{"type":"boolean"},"counter":{"type":"integer"}}}}}}POST leaders/_doc{ "leaders": [ { "except_1": true, "except_2": false }, { "except_1": false, "except_2": false } ]}GET leaders/_search{ "query": { "nested": { "path": "leaders", "inner_hits": {}, "query": { "bool": { "must": [ { "term": { "leaders.except_1": false } }, { "term": { "leaders.except_2": false } } ] } } } }}then GET leaders/_search{ "query": { "nested": { "path": "leaders", "inner_hits": {}, "query": { "bool": { "must": [ { "term": { "leaders.except_1": false } }, { "term": { "leaders.except_2": false } } ] } } } }}yielding { "hits":[ { "_index":"leaders", "_type":"_doc", "_id":"u-he8HEBG_KW3EFn-gMz", "_score":0.87546873, "_source":{ <-- default behavior "leaders":[ { "except_1":true, "except_2":false }, { "except_1":false, "except_2":false } ] }, "inner_hits":{ "leaders":{ "hits":{ "total":{ "value":1, "relation":"eq" }, "max_score":0.87546873, "hits":[ <------- only the matching nested subdocument { "_index":"leaders", "_type":"_doc", "_id":"u-he8HEBG_KW3EFn-gMz", "_nested":{ "field":"leaders", "offset":1 }, "_score":0.87546873, "_source":{ "except_1":false, "except_2":false } } ] } } } } ]}Furthermore, you can force the system to only return the inner_hits by saying "_source": "inner_hits" on the top-level of your search query. 这篇关于ElasticSearch按嵌套的布尔类型字段过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 06-03 08:05