3

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

4
  • 1
    This answer might help: stackoverflow.com/questions/31569422/… (hint: use filter_path) Commented Oct 3, 2017 at 5:46
  • I'm already using filter_path but I just want the _source portion without the hits and hits Commented Oct 3, 2017 at 5:55
  • 1
    You are only getting _source field only, it is just that it is wrapped in hits since it is a part of JSON._source is nested json element of hits. Commented Oct 3, 2017 at 5:58
  • You can use jq filter..this answer might help stackoverflow.com/questions/43758813/… Commented Oct 5, 2017 at 6:23

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.