Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 959
dchar Avatar asked Sep 15 '14 13:09

dchar


1 Answers

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

like image 89
Kumar Kailash Avatar answered Sep 30 '22 19:09

Kumar Kailash