2017-10-12 41 views
0

如何按年份和月份分组?如果我离开1个任期,我的查询就可以工作,例如Month。但我无法用多个词组分组。如何按多个词条对事件进行分组?

GET traffic-data/_search? 
{ 
"size":0, 
"query": { 
    "bool": { 
     "must": [ 
     { "match": { 
      "VehiclePlateNumber": "111" 
     }} 
     ] 
    } }, 
    "aggs" : { 
     "years" : { 
      "terms" : { 
       "field" : "Year" 
      }, 
      "aggs" : { 
       "months" : { "by_month" : { "field" : "Month" } } 
      } 
     } 
    } 
} 

回答

0

我认为你的问题的查询已经是接近,试试这个:

GET traffic-data/_search? 
{ 
    "size": 0, 
    "query": { 
    "bool": { 
     "must": [ 
     { 
      "match": { 
      "VehiclePlateNumber": "111" 
      } 
     } 
     ] 
    } 
    }, 
    "aggs": { 
    "years": { 
     "terms": { 
     "field": "Year", 
     "size": 100 
     }, 
     "aggs": { 
     "months": { 
      "terms": { 
      "size": 12, 
      "field": "Month" 
      } 
     } 
     } 
    } 
    } 
} 

编辑 - 我假设你的月是一个字符串关键字字段。让我知道如果情况并非如此(请包括映射),我会修改。

相关问题