我想过滤扩展统计聚合返回的统计。我基本上需要过滤掉avg
为0的所有值。
下面是一个示例查询,在这里我需要过滤这些值。我认为我应该应用 post_filter
。但是,我不确定要过滤出特定值时应如何应用后置过滤器。能否请你帮忙?
"aggs": {
"variable_grp": {
"terms": {
"field": "variable",
"size": 200,
"order": { "stats.avg": "asc" }
},
"aggs": {
"stats": {
"extended_stats": { "field": "value_num" }
}
}
}
},
"size":0
最佳答案
您可以使用bucket_selector
管道聚合来实现所需的功能:
{
"aggs": {
"variable_grp": {
"terms": {
"field": "variable",
"size": 200,
"order": {
"stats.avg": "asc"
}
},
"aggs": {
"stats": {
"extended_stats": {
"field": "value_num"
}
},
"avg_gt_0": {
"bucket_selector": {
"buckets_path": {
"avgStats": "stats.avg"
},
"script": "params.avgStats > 0"
}
}
}
}
}
}
关于elasticsearch - 如何在ElasticSearch中应用后过滤器以过滤掉某些值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54570873/