简体   繁体   中英

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": {}}}

在此处输入图片说明

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM