我怎样才能按年月分组?如果我离开一个术语,例如,Month,我的查询就能工作。但我不能用多个术语来分组。
GET traffic-data/_search?
{
"size":0,
"query": {
"bool": {
"must": [
{ "match": {
"VehiclePlateNumber": "111"
}}
]
} },
"aggs" : {
"years" : {
"terms" : {
"field" : "Year"
},
"aggs" : {
"months" : { "by_month" : { "field" : "Month" } }
}
}
}
}发布于 2017-10-12 21:52:41
我认为您的问题已经接近了,请尝试如下:
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"
}
}
}
}
}
}编辑-我假设你的月份是一个字符串关键字字段。如果不是这种情况,请告诉我(请包括映射),我将进行修改。
https://stackoverflow.com/questions/46717782
复制相似问题