dchar
dchar

Reputation: 1695

ElasticSearch get all fields even if their value is null

I want to search ElasticSearch and retrieve specific fields from all records, no matter their value. But response contains for each record only the fields whose value is not null. Is there a way to force ElasticSearch to return the exact same number of fields for all records?

Example Request:

{
    "fields" : ["Field1","Field2","Field3"],
    "query" : {
        "match_all" : {}
    }
}

Example Response:

{
    "hits": [
        {
            "fields": {
                "Field1": [
                    "bla"
                ],
                "Field2": [
                    "test"
                ]
            }
        },
        {
            "fields": {
                "Field1": [
                    "bla"
                ],
                "Field2": [
                    "test"
                ],
                "Field3": [
                    "somevalue"
                ]
            }
        }
    ]
}

My goal is to get something for "Field3" in the first hit.

Upvotes: 6

Views: 3354

Answers (1)

Kumar Kailash
Kumar Kailash

Reputation: 1395

As per the guide given in the following link, It clearly says that any fields which has null,[] or "" are not stored or not indexed in the document. Its an inverted index concept and has to be handled in the program explicitly.

link - http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/_dealing_with_null_values.html

Upvotes: 1

Related Questions