Friday, 2 October 2015

Elasticsearch: Retrieving parts of document


By default, GET statement returns entire document, some times you may interested in particular fields of document, in that case you can use query parameter _source.

GET xyz/employees/1?_source=hobbies,age

Above snippet returns hobbies and age of employee 1.

{
   "_index": "xyz",
   "_type": "employees",
   "_id": "1",
   "_version": 5,
   "found": true,
   "_source": {
      "hobbies": [
         "Watching movies",
         "Stamp collection",
         "Reading books",
         "Playing Cricket"
      ],
      "age": 30
   }
}

You can exclude metadata, by using following statement.

GET xyz/employees/1/_source?_source=hobbies,age

Above snippet return following output.

{
   "hobbies": [
      "Watching movies",
      "Stamp collection",
      "Reading books",
      "Playing Cricket"
   ],
   "age": 30
}



Prevoius                                                 Next                                                 Home

No comments:

Post a Comment