一尘不染

Spring搜索-从json响应中排除索引和类型

elasticsearch

当我对像这样的索引执行查询时:

{
   "_source":["bar"] , "size":100,
   "query": {
       "match_all": {}
   },
   "filter": {
       "type" : {
           "value" : "foo"
        }
    }
}

响应包括索引,类型等。但是我已经知道了索引和类型,因为我指定了它。此信息只会使json数据的大小膨胀。有没有办法从响应中排除这些?

这是我得到的:

{
"took": 31,
"timed_out": false,
"_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
    },
"hits": {
    "total": 364024,
    "max_score": 1,
    "hits": [
          {
        "_index": "foo_bar",
        "_type": "foo",
        "_id": "asdjj123123",
        "_score": 1,
        "_source": {
          "bar": "blablablabla"
    }
  }
,...

我想要的是这样的,所以没有 类型,分数,索引 的响应:

{
"took": 31,
"timed_out": false,
"_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
    },
"hits": {
    "total": 364024,
    "max_score": 1,
    "hits": [
          {
        "_id": "asdjj123123",
        "_source": {
          "bar": "blablablabla"
    }
  }
,...

阅读 232

收藏
2020-06-22

共1个答案

一尘不染

是的,从ES
1.6开始,您可以使用响应过滤,并且filter_path在查询中使用参数仅枚举响应中所需的内容:

curl -XGET 'localhost:9200/foo_bar/foo/_search?pretty&filter_path=hits.total,hits.max_score,hits.hits._id,hits.hits._source'
2020-06-22