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

user3313834
  • 7,327
  • 12
  • 56
  • 99
  • Possible duplicate of [Make elasticsearch only return certain fields?](https://stackoverflow.com/questions/9605292/make-elasticsearch-only-return-certain-fields) – whoopdedoo Sep 24 '17 at 23:24
  • @IddoE source filtering is something different. – Val Sep 25 '17 at 04:12

1 Answers1

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}}}}}}'
Val
  • 207,596
  • 13
  • 358
  • 360