按类型限制ElasticSearch聚合? [英] Restrict ElasticSearch aggregation by type?
本文介绍了按类型限制ElasticSearch聚合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何针对特定类型执行ElasticSearch聚合?我意识到您可以在请求Url中指定索引和/或类型,但是我想在两种不同类型上执行聚合。
How do you perform an ElasticSearch aggregation for a specific type? I realize that you can specify the index and/or type in the request Url, but I want to perform aggregations on two distinct types.
谢谢!
推荐答案
您可以按类型过滤聚合,然后使用子聚合。例如:
You could filter the aggregation by type, and then use sub-aggregations. For example:
{
"aggs": {
"Test 1": {
"filter": {
"type": {
"value": "type1"
}
},
"aggs": {
"agg_name": {
"terms": {
"field": "field1",
"size": 10
}
}
}
},
"Test 2": {
"filter": {
"type": {
"value": "type2"
}
},
"aggs": {
"agg_name": {
"terms": {
"field": "field2",
"size": 10
}
}
}
}
}
}
这篇关于按类型限制ElasticSearch聚合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文