ElasticSearch - 在嵌套字段上通过嵌套聚合排序聚合 [英] ElasticSearch - Ordering aggregation by nested aggregation on nested field

查看:3070
本文介绍了ElasticSearch - 在嵌套字段上通过嵌套聚合排序聚合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  {
query:{
match_all:{}
},
from:0,
size:0,
aggs:{
itineraryId:{
terms:{
field:iid,
size:2147483647,
order:[
{
price> price> price.max:desc
}
]
$ baggs:{
duration:{
stats:{
field:drn
}

price:{
nested:{
path:prl
},
aggs:{
price:{
filter:{
terms:{
prl.cc.keyword:[
USD
]

},
aggs:{
price:{
stats:{
field prl.spl.vl
}
}
}
}
}
}
}
}
}
}

这里,我收到错误,汇总顺序路径无效价格>价格> price.max]。条款桶只能在路径中由零个或多个单桶聚合构建的子聚合器路径上排序,最后一个桶或路径末尾的度量聚合。子路径[价格]指向非单桶聚合



查询工作正常,如果我按持续时间聚合排序,如

 order:[
{
duration.max:desc
}

所以有什么办法可以通过嵌套字段上的嵌套聚合排序聚合,即如下所示?

 订单:[
{
price> price> price.max:desc
}


解决方案

正如Val在评论中指出的,ES不支持它。 / p>

然后,您可以先聚合嵌套聚合,然后使用反向嵌套聚合来聚合文档根目录中的持续时间。



https:// www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-reverse-nested-aggregation.html


{
  "query": {
    "match_all": {}
  },
  "from": 0,
  "size": 0,
  "aggs": {
    "itineraryId": {
      "terms": {
        "field": "iid",
        "size": 2147483647,
        "order": [
          {
            "price>price>price.max": "desc"
          }
        ]
      },
      "aggs": {
        "duration": {
          "stats": {
            "field": "drn"
          }
        },
        "price": {
          "nested": {
            "path": "prl"
          },
          "aggs": {
            "price": {
              "filter": {
                "terms": {
                  "prl.cc.keyword": [
                    "USD"
                  ]
                }
              },
              "aggs": {
                "price": {
                  "stats": {
                    "field": "prl.spl.vl"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

Here, I am getting error that "Invalid terms aggregation order path [price>price>price.max]. Terms buckets can only be sorted on a sub-aggregator path that is built out of zero or more single-bucket aggregations within the path and a final single-bucket or a metrics aggregation at the path end. Sub-path [price] points to non single-bucket aggregation"

query works fine if I order by duration aggregation like

"order": [
      {
        "duration.max": "desc"
      }

So is there any way to Order aggregation by nested aggregation on nested field i.e something like below ?

"order": [
      {
        "price>price>price.max": "desc"
      }

解决方案

As Val has pointed out in the comments ES does not support it yet.

Till then you can first aggregate the nested aggregation and then use the reverse nested aggregation to aggregate the duration, that is present in the root of the document.

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-reverse-nested-aggregation.html

这篇关于ElasticSearch - 在嵌套字段上通过嵌套聚合排序聚合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆