Sachin
Sachin

Reputation: 71

return only _source data from elasticsearch query

I want to get only _source fields by the query.but it returns hits which are unnecessary for me.so how to remove this hits before the _source data.

GET fms/user/_search?filter_path=hits.hits._source{"query": {"match_all": {}}}

enter image description here

Upvotes: 3

Views: 4736

Answers (1)

Girdhar Sojitra
Girdhar Sojitra

Reputation: 678

If you want to filter _source fields, you should consider combining the already existing _source parameter with the filter_path parameter like this:

POST /library/book?refresh
{"title": "Book #1", "rating": 200.1}
POST /library/book?refresh
{"title": "Book #2", "rating": 1.7}
POST /library/book?refresh
{"title": "Book #3", "rating": 0.1}

GET /_search?filter_path=hits.hits._source&_source=title&sort=rating:desc

{
  "hits" : {
    "hits" : [ {
      "_source":{"title":"Book #1"}
    }, {
      "_source":{"title":"Book #2"}
    }, {
      "_source":{"title":"Book #3"}
    } ]
  }
}

For more details, go through at https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html

As you are already using filter_path, you are already getting only source field only.

Upvotes: 1

Related Questions