elastic search 5.1 why stored_fields does not return asked field?

6.4k views Asked by At

In Elastic Search 5.1 I am making basic request with stored_fields body argument (new name for old fields argument) for retrieving the value of a specific field.

But my request give no field value in answer except _index, _type, _id and _score

I Give you sample for context:

I create index and mapping with:

 PUT /base_well
    {
        "mappings": {
            "person": {
                   "properties": {
                       "first_name":{
                           "type": "string"
                       },
                         "last_name":{
                           "type": "string"
                       },
                       "age":{
                           "type": "long"
                       }
                   }
            }
        }
    }

I populate :

  POST /base_well/person
        {
            "first_name":"James",
            "last_name" : "Mopo",
            "Age" : 21
        }

    POST /base_well/person
    {
        "first_name":"Polo",
        "last_name" : "Rodriguez",
        "Age" : 36
    }

    POST /base_well/person
    {
        "first_name":"Marc Aurelien",
        "last_name" : "Poisson",
        "Age" : 26
    }

    POST /base_well/person
    {
        "first_name":"Mustapha",
        "last_name" : "Bulutu M'Bo",
        "Age" : 47
    }

I do my request with:

    POST  /base_well/person/_search
{
   "stored_fields": ["first_name"]

}

And it give me an answere without the requested field fiest_person:

{
   "took": 4,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 8,
      "max_score": 1,
      "hits": [
         {
            "_index": "base_well",
            "_type": "person",
            "_id": "AVlFYzihcR_Z5VPUXUCL",
            "_score": 1
         },
         {
            "_index": "base_well",
            "_type": "person",
            "_id": "AVlFiv3acR_Z5VPUXUCa",
            "_score": 1
         },
         {
            "_index": "base_well",
            "_type": "person",
            "_id": "AVlFiwUKcR_Z5VPUXUCb",
            "_score": 1
         },
         {
            "_index": "base_well",
            "_type": "person",
            "_id": "AVlFYx2LcR_Z5VPUXUCI",
            "_score": 1
         },
         {
            "_index": "base_well",
            "_type": "person",
            "_id": "AVlFYyhScR_Z5VPUXUCJ",
            "_score": 1
         },
         {
            "_index": "base_well",
            "_type": "person",
            "_id": "AVlFYzIJcR_Z5VPUXUCK",
            "_score": 1
         },
         {
            "_index": "base_well",
            "_type": "person",
            "_id": "AVlFivgzcR_Z5VPUXUCZ",
            "_score": 1
         },
         {
            "_index": "base_well",
            "_type": "person",
            "_id": "AVlFiw2qcR_Z5VPUXUCc",
            "_score": 1
         }
      ]
   }
}

Anybody could explain me to do it and how it works please?

1

There are 1 answers

3
Val On BEST ANSWER

By default, the document fields are not stored, i.e. in your mapping you don't specify store: true for each of them.

Hence, "stored_fields": ["first_name"] will not be able to return the first_name field since it's not stored.

You can use source filtering instead and specify "_source": ["first_name"] in your query, that will work.