2014-10-09 73 views
1

我正在嘗試構建一個elasticsearch查詢來計算特定字段在特定範圍內的文檔數量。這種聚合也包含在日期直方圖聚合中,但我認爲這不是問題的目的。如何計算字段在特定範圍內的文檔數量?

示例數據:

ID: Score 
01: 4 
02: 5 
03: 10  
04: 9 

我想計數的文件數量,其中「分數」爲> = 9。我有這個匯聚中試圖腳本和過濾器,但我不能得到它工作。

該彙總計算所有文檔,而不僅僅是與腳本匹配的文檔。

"aggs": { 
    "report_days": { 
     "date_histogram": { 
      "field": "Date", 
      "interval": "day" 
     }, 
     "aggs": { 
      "value_count": { 
       "field": "Score", 
       "script": "_value >=9" 
      } 
     } 
    } 
} 

這在聚集給了我一個解析失敗,說Parse Failure [Expected [START_OBJECT] under [field], but got a [VALUE_STRING] in [value_count]]

"aggs": { 
    "report_days": { 
     "date_histogram": { 
      "field": "Date", 
      "interval": "day" 
     }, 
     "aggs": { 
      "value_count": { 
       "field": "Score", 
       "filter": { 
        "range": { 
         "Score": { 
          "gte": 9 
         } 
        } 
       } 
      } 
     } 
    } 
} 

感謝您的任何建議!

回答

0

運行查詢(「score:> 9」)並檢查命中 - >總值。請參閱the doc中的示例。

相關問題