Elasticsearch aggregation group with null key
Here is the data on my elasticsearch server:
{"system": "aaa"},
{"system": "bbb"},
{"system": null}
I want to get statistics for the system. then I made a request:
{
"aggs" : {
"myAggrs" : {
"terms" : { "field" : "system" }
}
}
it gives me the result:
{
"key": "aaa",
"doc_count": 1
},
{
"key": "bbb",
"doc_count": 1
}
but "key" : null
not included in the result, how can i get it? here is my expected result:
{
"key": "aaa",
"doc_count": 1
},
{
"key": "bbb",
"doc_count": 1
},
{
"key": null,
"doc_count": 1
}
+3
source to share
1 answer
I don't think you can do it with terms
. Try with a different aggregation:
{
"aggs": {
"myAggrs": {
"terms": {
"field": "system"
}
},
"missing_system": {
"missing": {
"field": "system"
}
}
}
}
And the result will be:
"aggregations": {
"myAggrs": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "aaa",
"doc_count": 1
},
{
"key": "bbb",
"doc_count": 1
}
]
},
"missing_system": {
"doc_count": 1
}
}
+6
source to share