如何按多个术语对事件进行分组?
How to group events by multiple terms?
如何按年月分组?如果我保留 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" } }
}
}
}
}
我认为你的问题的查询已经结束,试试这个:
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"
}
}
}
}
}
}
编辑 - 我假设您的月份是一个字符串关键字字段。如果不是这种情况请告诉我(请包括映射),我会修改。
如何按年月分组?如果我保留 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" } }
}
}
}
}
我认为你的问题的查询已经结束,试试这个:
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"
}
}
}
}
}
}
编辑 - 我假设您的月份是一个字符串关键字字段。如果不是这种情况请告诉我(请包括映射),我会修改。