首页 > 解决方案 > aggregation_execution_exception : 聚合顺序路径无效,子路径指向非单桶聚合

问题描述

当我运行 es aggration 时:

"aggregations": {
    "author": {
      "terms": {
        "field": "author",
        "size": 100, 
        "min_doc_count": 1,
        "shard_min_doc_count": 0,
        "show_term_doc_count_error": false,
        "order": {
          "interactions-c>interactions-sum": "desc"
        }
      },
      "aggregations": {
        "interactions-c": {
          "children": {
            "type": "interactions"
          },
          "aggregations": {
            "interactions-sum": {
              "sum": {
                "field": "interactions.likes"
              }
            }
          }
        }
      }
    }
}

例外:

{
  "error" : {
    "root_cause" : [
      {
        "type" : "aggregation_execution_exception",
        "reason" : "Invalid aggregation order path [interactions-c>interactions-sum]. 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 [interactions-c] points to non single-bucket aggregation"
      }
    ],
    "type" : "search_phase_execution_exception",
    "reason" : "all shards failed",
    "phase" : "query",
    "grouped" : true,
    "failed_shards" : [
      {
        "shard" : 0,
        "index" : "article_20200910",
        "node" : "fLYvCQjfTEKG0QIivtn3Hg",
        "reason" : {
          "type" : "aggregation_execution_exception",
          "reason" : "Invalid aggregation order path [interactions-c>interactions-sum]. 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 [interactions-c] points to non single-bucket aggregation"
        }
      }
    ]
  },
  "status" : 500
}

这是我的索引映射:

{
  "article" : {
    "aliases" : { },
    "mappings" : {
      "properties" : {
        "author" : {
          "type" : "keyword"
        },
        "interactions" : {
          "properties" : {
            "comments" : {
              "type" : "long"
            },
            "dislikes" : {
              "type" : "long"
            },
            "forwards" : {
              "type" : "long"
            },
            "likes" : {
              "type" : "long"
            },
            "views" : {
              "type" : "long"
            }
          }
        },
        "joinField" : {
          "type" : "join",
          "eager_global_ordinals" : false,
          "relations" : {
            "article" : [
              "interactions"
            ]
          }
        }
      }
    }
  }
}

我创建了一个使用连接字段(父:文章;子:交互)的索引,我想要什么:

  1. 按作者聚合交互次数(作者是父索引字段,交互是子字段)
  2. 然后按interations sum value desc排序

但是es说childern aggs不是一个单独的桶aggs!那么有什么办法吗?

标签: elasticsearch

解决方案


推荐阅读