0
elasticsearch 5.2Elasticsearch 5 |过滤器嵌套对象和嵌套聚合计数
我想通过嵌套对象state.id = 101筛选我的项目,并通过state.id筛选所有项目的聚合计数。有一些项目的状态标识为101,102和103.
聚合计数现在仅限于state.id 101.我只希望获得带有state.id = 101的项目和所有状态ID的聚合计数。
我该怎么做?
GET index/items/_search
{
"query": {
"nested" : {
"path" : "state",
"query": {
"bool": {
"filter": {
"term": { "state.id": 101 }
}
}
}
}
},
"aggs" : {
"state" : {
"nested" : {
"path" : "state"
},
"aggs" : {
"count" : { "terms" : { "field" : "state.id" } }
}
}
}
}
谢谢。正是我需要的。还有一个问题。我想将当前的聚合上下文缩小到一组特定的文档。我如何在嵌套聚合中使用过滤器聚合。 [链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filter-aggregation.html) – Joost
酷,很高兴它帮助。我已经更新了我的答案。 – Val
Thx。但是,我想过滤嵌套对象上的聚合。 ''' “过滤器”:{ “术语”:{ “state.id”:[101,102] }} , ''' 而只能从 “state.id” 文件:101像上面一样。 – Joost