elasticsearch子聚合失败

时间:2016-07-15 13:21:22

标签: elasticsearch aggregation

在ES 2.2上,我正在尝试以下查询:

{
  "query": {
    "bool": {
      "must": {
        "match_all": {}
      },
      "filter": {
        "range": {
          "startDate": {
            "gt": "2016-07-01"
          }
        }
      }
    }
  },
  "aggs": {
    "numbera": {
      "terms": {
        "field": "numbera",
        "size": 0,
        "aggs": {
          "some": {
            "avg": {
              "field": "callDuration"
            }
          }
        }
      }
    }
  }
}

会出现以下错误:

{
    "type": "search_parse_exception",
    "reason": "Unknown key for a START_OBJECT in [numbera]: [aggs].",
    "line": 20,
    "col": 18
}

我很遗憾,该查询出了什么问题?

从查询中删除子聚合会给我一个正确的结果。

1 个答案:

答案 0 :(得分:0)

嵌套aggs应与"terms": {...}处于同一级别,而不是嵌套在其下。

"aggs": {
  "numbera": {
    "terms": {
      "field": "numbera",
      "size": 0
    },
    "aggs": {
      "some": {
        "avg": {
          "field": "callDuration"
        }
      }
    }
  }
}