2015-08-06 11:24:29 -04:00
|
|
|
[[null-value]]
|
|
|
|
=== `null_value`
|
|
|
|
|
|
|
|
A `null` value cannot be indexed or searched. When a field is set to `null`,
|
|
|
|
(or an empty array or an array of `null` values) it is treated as though that
|
|
|
|
field has no values.
|
|
|
|
|
|
|
|
The `null_value` parameter allows you to replace explicit `null` values with
|
|
|
|
the specified value so that it can be indexed and searched. For instance:
|
|
|
|
|
2019-09-06 11:31:13 -04:00
|
|
|
[source,console]
|
2015-08-06 11:24:29 -04:00
|
|
|
--------------------------------------------------
|
2020-07-27 15:58:26 -04:00
|
|
|
PUT my-index-000001
|
2015-08-06 11:24:29 -04:00
|
|
|
{
|
|
|
|
"mappings": {
|
2019-01-22 09:13:52 -05:00
|
|
|
"properties": {
|
|
|
|
"status_code": {
|
|
|
|
"type": "keyword",
|
|
|
|
"null_value": "NULL" <1>
|
2015-08-06 11:24:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-27 15:58:26 -04:00
|
|
|
PUT my-index-000001/_doc/1
|
2015-08-06 11:24:29 -04:00
|
|
|
{
|
|
|
|
"status_code": null
|
|
|
|
}
|
|
|
|
|
2020-07-27 15:58:26 -04:00
|
|
|
PUT my-index-000001/_doc/2
|
2015-08-06 11:24:29 -04:00
|
|
|
{
|
|
|
|
"status_code": [] <2>
|
|
|
|
}
|
|
|
|
|
2020-07-27 15:58:26 -04:00
|
|
|
GET my-index-000001/_search
|
2015-08-06 11:24:29 -04:00
|
|
|
{
|
|
|
|
"query": {
|
|
|
|
"term": {
|
|
|
|
"status_code": "NULL" <3>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2019-09-06 11:31:13 -04:00
|
|
|
|
2015-08-06 11:24:29 -04:00
|
|
|
<1> Replace explicit `null` values with the term `NULL`.
|
|
|
|
<2> An empty array does not contain an explicit `null`, and so won't be replaced with the `null_value`.
|
|
|
|
<3> A query for `NULL` returns document 1, but not document 2.
|
|
|
|
|
2020-07-07 14:59:35 -04:00
|
|
|
IMPORTANT: The `null_value` needs to be the same data type as the field. For
|
2016-03-18 12:01:27 -04:00
|
|
|
instance, a `long` field cannot have a string `null_value`.
|
2018-01-31 09:04:11 -05:00
|
|
|
|
|
|
|
NOTE: The `null_value` only influences how data is indexed, it doesn't modify
|
|
|
|
the `_source` document.
|