怎么没有得到" _shards"在elasticsearch查询答案

时间:2017-09-24 18:26:11

标签: elasticsearch

我在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 }'

我怎样才能避免得到答案""和" _shards"并且只有"命中"字典?

$ 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 } }
    ]
  }
}
$ 

正如@IddoE所说它不是关于源过滤

1 个答案:

答案 0 :(得分:3)

您需要使用filter_path查询字符串参数才能包含hits部分:

                                            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}}}}}}'