我将这2个文档编入索引:
POST my_index/my_type/1
{
"name": "Nephi",
"x": 5
}
POST my_index/my_type/2
{
"name": "Lehi",
"x": 10
}
这是我的搜索请求:
POST my_index/my_type/_search?size=0
{
"aggs": {
"some_terms_agg": {
"terms": {
"field": "name",
"order": {
"the_script_bucket": "asc"
}
},
"aggs": {
"the_sum": {
"sum": {
"field": "x"
}
},
"the_avg": {
"avg": {
"field": "x"
}
},
"the_script_bucket": {
"bucket_script": {
"buckets_path": {
"a": "the_sum.value",
"b": "the_avg.value"
},
"script": "a + b"
}
}
}
}
}
}
我收到这样的错误:
Invalid term-aggregator order path [the_script_bucket]. Unknown aggregation [the_script_bucket]
但是,当我将
the_script_bucket
更改为the_sum
或the_avg
之类的另一个聚合时,它可以正常工作。我确定这是因为the_script_bucket
是管道聚合,但是我希望根据the_script_bucket
对术语进行排序,因此(例如)我可以查看100,000个文档的前10个值。那可能吗?
最佳答案
看来这是Elasticsearch中目前尚待解决的问题
https://github.com/elastic/elasticsearch/issues/8486
https://discuss.elastic.co/t/ordering-terms-aggregation-based-on-pipeline-metric/31839
关于elasticsearch - Elasticsearch通过管道bucket_script聚合对术语进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37799130/