2016-09-06 56 views
0

我期待找到每個擴展的總和。 JSON文件包含ElasticSearch每個擴展的查詢獲得其長度的總和

示例代碼

 {"index":{"_id":"202"}} 
     "length":500000 
     "extension":".jpeg" 

輸出想要

重點:JPEG千萬 重點:DOCX 20000000

試過代碼

 GET /crud_sample2/Customer_Info/_search?extension 
      { 
      "aggs": { 
      "sum": { 
      "terms": { 
       "field": "length" 
       } 
      } 
      } 
     } 

輸出

「鑰匙」:500000 「doc_count」:15

+0

http://stackoverflow.com/questions/39354830/trying-to-upload-json-files-使用命令行錯誤消息彈性搜索 – Nicola

回答

0

試試這個

GET /crud_sample2/Customer_Info/_search 
{ 
    "aggs": { 
    "sum": { 
     "terms": { 
     "field": "extension", 
     "order": {"total_length": "desc"} 
     }, 
     "aggs": { 
     "total_length": { 
      "sum": { 
      "field": "length" 
      } 
     } 
     } 
    } 
    } 
} 
+0

非常感謝。 – Nicola

+0

有反正你可以像「排序」排序是:{ 「total_length」:「遞減」 }, 「大小」:10 } – Nicola

+0

完美,感謝 – Nicola