[英]filtering an elasticsearch query by aggregations
Hi my question is two parts.嗨,我的问题分为两个部分。 I've got a dataset that looks like我有一个看起来像的数据集
{name: "foo",
contracts: [{size: 1}, {size: 3}]},
{name: "bar",
contracts: [{size: 100}, {size: 300}]}
using the metrics aggregation I can the average size of ALL the items.使用指标聚合,我可以计算出所有项目的平均大小。 1+3+100+300 / 4, however is it possible to return the average contract size per item? 1+3+100+300 / 4,但是是否可以返回每个项目的平均合同大小?
I'd like to be able to return我希望能够回来
{name: "foo",
averageContract: 2},
{name: "bar",
averageContract: 200},
Additionally would it be possible to get that value AND filter on it?另外是否有可能获得该值并对其进行过滤?
eg match where averageContract > 100?例如匹配 averageContract > 100?
Try this:尝试这个:
{
"size": 0,
"aggs": {
"item": {
"terms": {
"field": "name.keyword",
"size": 10
},
"aggs": {
"averageContract": {
"avg": {
"field": "contracts.size"
}
},
"selector_avg_contract": {
"bucket_selector": {
"buckets_path": {
"avg": "averageContract"
},
"script": "params.avg > 100"
}
}
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.