Hello. We've been migrating from ES 7 version to 8.5 and discovered this weird behavior.
In Kibana I can index a test document with a null field value and it will get indexed and will be present in the index.
PUT my-index-000001
{
"mappings": {
"properties": {
"status": {
"type": "text"
},
"docType": {
"type": "text"
}
}
}
}
PUT my-index-000001/_doc/1
{
"status": null,
"docType":"Contract"
}
GET my-index-000001/_doc/1
Field "status" is present in document 1 and has a null value:
{
"_index": "my-index-000001",
"_id": "1",
"_version": 1,
"_seq_no": 0,
"_primary_term": 1,
"found": true,
"_source": {
"status": null,
"docType": "War"
}
}
When I index a second document with a null docType using Java API it doesn't get indexed:
@Data
public class Document {
private String status;
private String docType;
}
Document doc = new Document();
doc.setStatus("new");
ElasticsearchClient esClient = getClient();
esClient.index(i -> i.index("my-index-000001").id("2").document(doc));
This is how the document looks like in the index:
{
"_index": "my-index-000001",
"_id": "2",
"_version": 1,
"_seq_no": 1,
"_primary_term": 1,
"found": true,
"_source": {
"status": "new"
}
}
docType is missing.
I get that we can't search null fields but we can't even index them and include in JSON? If so, I would have expected the same behavior in Kibana and Java API. Am I missing something in my Java code? Is it possible to include null fields in the indexed documents? I need a unified JSON structure for all my indexed documents, searching on nullable fields is not needed.