它与先前的答案并没有真正的不同。您需要做的就是稍微修改字段名称,以考虑其他嵌套。除此之外,映射中无需进行任何更改。请注意,此查询无需映射更改就可以工作,因为
response和
results都是带有单个元素的数组,如果不是这种情况,它将涉及更多问题,并且需要映射更改和其他查询。
现在查询如下所示:
{ "size": 0, "aggregations": { "by_keyword": { "terms": { "field": "keyword" }, "aggs": { "prop_1_count": { "nested": { "path": "response.results.items" }, "aggs": { "prop_1": { "terms": { "field": "response.results.items.prop.item_property_1" } } } } } } }}结果:
{ ... "aggregations" : { "by_keyword" : { "doc_count_error_upper_bound" : 0, "sum_other_doc_count" : 0, "buckets" : [ { "key" : "different keyword", "doc_count" : 1, "prop_1_count" : { "doc_count" : 2, "prop_1" : { "doc_count_error_upper_bound" : 0, "sum_other_doc_count" : 0, "buckets" : [ { "key" : "A", "doc_count" : 1 }, { "key" : "C", "doc_count" : 1 } ] } } }, { "key" : "my keyword", "doc_count" : 1, "prop_1_count" : { "doc_count" : 3, "prop_1" : { "doc_count_error_upper_bound" : 0, "sum_other_doc_count" : 0, "buckets" : [ { "key" : "A", "doc_count" : 2 }, { "key" : "B", "doc_count" : 1 } ] } } } ] } }}


