here is the data in my elasticsearch server:
{"system": "aaa"},
{"system": "bbb"},
{"system": null}
I want to get the statistics for system. then I did the query:
{
"aggs" : {
"myAggrs" : {
"terms" : { "field" : "system" }
}
}
it gives me the result:
{
"key": "aaa",
"doc_count": 1
},
{
"key": "bbb",
"doc_count": 1
}
but the "key" : null
is not included in the result, how can I get it?
here is my expect result:
{
"key": "aaa",
"doc_count": 1
},
{
"key": "bbb",
"doc_count": 1
},
{
"key": null,
"doc_count": 1
}
I don't think you can do this with terms
. Try with another 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
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With