ElasticSearch - Ordering aggregation by nested aggregation on nested field

老子叫甜甜 提交于 2019-12-04 05:26:33

问题


{
  "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"
      }

回答1:


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



来源:https://stackoverflow.com/questions/43451667/elasticsearch-ordering-aggregation-by-nested-aggregation-on-nested-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!