Terms and Histogram aggregations support a missing value option, which will default any missing or null values to a specified value. But the documentation does not mention this option for Date Range aggregations.
It looks like support for this feature was added to several aggregations in this pull request, but not Date Range aggregations:
Eventhough the docs do not mention support for it, using this option in a date range agg does seem to work. Is this just not officially supported for Date Range? Is this option safe to use?
I have the following query, which returns any docs with a null user_date_of_birth in the 'Unknown' bucket:
Request:
GET myindex/user/_search
{
"aggs": {
"age_groups": {
"range": {
"field": "user_date_of_birth",
"missing": "1899-12-31",
"ranges": [
{
"key": "Unknown",
"to": "1900-01-01"
},
{
"from": "1950-01-01"
}
]
},
"aggs": {
"age_group_count": {
"value_count": {
"field": "user_id"
}
}
}
}
}
}
Response:
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1,
"hits": [
{
"_index": "myindex",
"_type": "user",
"_id": "2",
"_score": 1,
"_source": {
"user_id": 2,
"user_date_of_birth": null
}
},
{
"_index": "myindex",
"_type": "user",
"_id": "1",
"_score": 1,
"_source": {
"user_id": 1,
"user_date_of_birth": "1950-01-02"
}
}
]
},
"aggregations": {
"age_groups": {
"buckets": [
{
"key": "Unknown",
"to": -2208988800000,
"to_as_string": "1900-01-01T00:00:00.000Z",
"doc_count": 1,
"age_group_count": {
"value": 1
}
},
{
"key": "1950-01-01T00:00:00.000Z-*",
"from": -631152000000,
"from_as_string": "1950-01-01T00:00:00.000Z",
"doc_count": 1,
"age_group_count": {
"value": 1
}
}
]
}
}
}