You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在OpenSearch API请求中过滤响应,仅获取hits内的_source?

OpenSearch查询仅返回hits内的_source数据解决方案
  • 问题根源:你的请求参数分隔符使用错误,HTTP请求中多个参数需要用&分隔,而非重复使用?,这导致filter_path参数未被正确解析,元数据因此依然被返回。

  • 正确请求格式:

    GET http://localhost:9200/my_index/_search?q="product1234"&format=json&filter_path=hits.hits._source
    

    发送该请求后,返回结果会仅保留hits.hits下的_source字段,结构如下:

    {
      "hits" : {
        "hits" : [
          { "_source" : { ... } },
          { "_source" : { ... } }
        ]
      }
    }
    
  • 进阶优化:

    • 若只想返回_source内的特定字段,可添加_source参数指定字段,比如仅返回product_id:
      GET http://localhost:9200/my_index/_search?q="product1234"&format=json&filter_path=hits.hits._source&_source=product_id
      
    • 若期望直接得到[{"_source": {...}}, ...]格式的数组,OpenSearch服务端无法直接生成该结构,需在客户端对返回结果做简单提取,比如通过代码取response.hits.hits即可得到目标数组。

内容的提问来源于stack exchange,提问作者Juki

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 00:45:34