ElasticSearch聚合中的自定义排序

hk8txs48  于 2021-06-13  发布在  ElasticSearch
关注(0)|答案(0)|浏览(413)

我对ElasticSearch还不熟悉。目前我正在使用elasticsearch 7.10。我的ElasticSearchMap是:

"mappings" : {
  "home_index_doc" : {
    "properties" : {
      "city" : {
        "type" : "nested",
        "properties" : {
          "country" : {
            "type" : "nested",
            "properties" : {
              "name" : {
                "type" : "text"
              }
            }
          },
          "name" : {
            "type" : "keyword"
          }
        }
      },
      "home_type" : {
        "type" : "nested",
        "properties" : {
          "types" : {
            "type" : "keyword"
          }
        }
      },
      ...
    }
  }
}

我的聚合查询是:

GET home-index/home_index_doc/_search
{
  "size": 0,
  "aggs": {
    "all_cities": {
      "nested": {
        "path": "city"
      },
      "aggs": {
        "city_name": {
          "terms": {
            "field": "city.name",
            "order": [
               {
              "by_home_types>all_home_types>home_type": "desc"
            }
              ]
          },
          "aggs": {
            "by_home_types": {
              "reverse_nested": {},
              "aggs": {
                "all_home_types": {
                  "nested": {
                    "path": "home_type"
                  },
                  "aggs": {
                    "home_type": {
                      "value_count": {
                        "field": "home_type.types"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

我想根据房屋类型对城市垃圾桶进行分类。但我得到了以下例外:

{
                "type": "aggregation_execution_exception",
                "reason": "Invalid aggregation order path [by_home_types>all_home_types>home_type]. 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. [by_home_types] is not single-bucket."
            }

无法找出上述聚合的问题所在。任何帮助都将不胜感激。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题