【问题标题】:Elasticsearch: avoid to return "sort" value in the resultsetElasticsearch:避免在结果集中返回“排序”值
【发布时间】:2016-05-07 00:46:31
【问题描述】:

我有这个简单的搜索:

{
   "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)。

【问题讨论】:

    标签: php json elasticsearch overflow


    【解决方案1】:

    您绝对不能在查询中使用response filtering 返回sort

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

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

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

    【讨论】:

    • 还有其他方法吗?目前我只能向 ES 发出 POST 请求,并且无法直接访问此类参数,我只能更改请求的正文!
    • 您也可以在您发布的 URL 中添加查询字符串参数,即使您也在正文中发送了有效负载。可行吗?
    • 不,我不能向 ES 发送额外的帖子数据,但索引和搜索正文:(
    • 您能说明一下您是如何发送查询的吗?
    • 我目前使用的内部 API 只接受两个参数:搜索的索引和转发到 ES 的搜索正文(我之前在问题中粘贴的那个)
    猜你喜欢
    • 2011-07-24
    • 1970-01-01
    • 2011-03-20
    • 2021-10-21
    • 1970-01-01
    • 1970-01-01
    • 2018-08-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多