弹性搜索:避免在结果集中返回“排序”值


Elasticsearch: avoid to return "sort" value in the resultset

>我有一个简单的搜索:

{
   "from": 0,
   "size": 5,
   "query": {
      "match_all": {}
   },
   "_source": [
     "info"
   ],
   "sort": {
      "date": {
         "order": "desc"
      }
   }
}

结果集为:

"hits":{
  "hits":[
    {"sort":[-9223372036854775808 ], "_type": "reports", "_source": …},
    {"sort":[-9223372036854775808 ], "_type": "reports", "_source": …},
    {"sort":[-9223372036854775808 ], "_type": "reports", "_source": …},
    {"sort":[-9223372036854775808 ], "_type": "reports", "_source": …},
    {"sort":[-9223372036854775808 ], "_type": "reports", "_source": …}
  ],
  "total": 38,
  "max_score": null
},
"_shards":{
  "successful": 15,
  "failed": 0,
  "total": 15
},
"took": 11,
"timed_out": false

是否可以从结果集中删除"sort":[-9223372036854775808 ]字段?我必须用这个结果创建一个 json,但由于这个字段中的这个大整数,我得到了一个错误 ( json_decode(): integer overflow detected )。

您绝对不能通过在查询中使用响应筛选来返回sort

在查询的 URL 中,只需添加以下查询字符串参数:

...&filter_path=hits.hits._source,hits.hits._id,hits.hits._type,hits.hits._index

您将获得每个命中中的所有 JSON 字段,除了sort字段。