2016-07-15 109 views
0

在ES 2.2,我想下面的查詢:elasticsearch子聚集失敗

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

我很茫然,什麼是錯的查詢?

從查詢中刪除子聚合給了我一個正確的結果。

回答

0

嵌套的aggs應該與"terms": {...}處於同一級別,而不是嵌套在它下面。

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