The noSQL nature of the Elasticsearch database involves dynamic mapping, so a document with a field with a null
value is not indexed.
From the null_value
property documentation:
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.
You may want to leverage that parameter to explicitly mark null values but not all field types support it.
Here some testing to play with:
# Clean up
DELETE discuss-341052
# Create an index with some null values
PUT discuss-341052
{
"settings": {
"number_of_replicas": 0
},
"mappings": {
"properties": {
"title": { "type": "text"},
"category": { "type": "keyword", "null_value": "NULL"},
"description": { "type": "text"},
"score": { "type": "float", "null_value": -1}
}
}
}
# Add some data with some rows without fields,
# others with explicit null values
POST discuss-341052/_bulk
{ "index": {} }
{ "title": "a", "category": "a", "description": "a desc", "score": 1}
{ "index": {} }
{ "title": "b", "category": "a", "description": "a desc", "score": 1}
{ "index": {} }
{ "title": "c", "category": "b", "description": "a desc", "score": 1}
{ "index": {} }
{ "title": "c", "category": "b"}
{ "index": {} }
{ "title": "c", "category": "c", "description": null, "score": -1}
{ "index": {} }
{ "title": "d", "category": "NULL", "description": "a desc", "score": -1}
# Create a Kibana Data View
POST kbn:/api/data_views/data_view
{
"data_view": {
"title": "discuss-341052"
}
}
So on Discover some documents don't have the missing fields as you mentioned
But the last document has the explicit (and searchable) null documents