1

I have this simple data on ES::

curl -XPUT localhost:9200/dt/art/1 -d '{ "age": 77 }'
curl -XPUT localhost:9200/dt/art/2 -d '{ "age": 19 }'
curl -XPUT localhost:9200/dt/art/3 -d '{ "age": 42 }'
curl -XPUT localhost:9200/dt/art/4 -d '{ "age": 33 }'

How can I avoid to get in the answer the "took" and the "_shards" and only the have "hits" dictionary?

$ curl "localhost:9200/dt/art/_search?pretty" -d'{
    "query": {
      "bool": { "must": { "match_all": {} },
                "filter": {
                  "range": {
                  "age": { "gte": 20, "lte": 50}}}}}}'


{ "took" : 8, "timed_out" : false,
  "_shards" : { "total" : 5, "successful" : 5, "skipped" : 0, "failed" : 0 },
  "hits" : {
    "total" : 2,
    "max_score" : 1.0,
    "hits" : [
      { "_index" : "dt", "_type" : "art", "_id" : "4", "_score" : 1.0,
        "_source" : { "age" : 33 } },
      { "_index" : "dt", "_type" : "art", "_id" : "3", "_score" : 1.0,
        "_source" : { "age" : 42 } }
    ]
  }
}
$ 

as @IddoE say it's not about source filtering

2

1 Answer 1

3

You need to use the filter_path query string parameter in order to only include the hits part:

                                            add this
                                               |
                                               v
curl "localhost:9200/dt/art/_search?pretty&filter_path=hits" -d'{
    "query": {
      "bool": { "must": { "match_all": {} },
                "filter": {
                  "range": {
                  "age": { "gte": 20, "lte": 50}}}}}}'
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.