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

如何在Elasticsearch中仅返回查询结果的_source字段?

How to Return Only _source Content in Elasticsearch Search Results

Hey there! Let's solve this—you want to cut through all the default extra fields (like took, timed_out, _shards, max_score, plus metadata like _id/_score in each hit) and only get the _source content from your Elasticsearch queries. Here are the most straightforward ways to do it:

1. Use the filter_path Parameter (Simplest & Most Effective)

This parameter lets you filter the entire JSON response to keep only the paths you care about. To fetch just the _source entries from your search hits, add this to your request:

Example with URL Parameter:

GET /your_target_index/_search?filter_path=hits.hits._source

Example with Request Body:

POST /your_target_index/_search
{
  "filter_path": ["hits.hits._source"],
  "query": {
    // Replace with your actual query (e.g., match, term, etc.)
    "match_all": {}
  }
}

This response will only include the array of _source objects—no extra top-level fields or hit metadata cluttering things up.

2. Combine _source and filter_path (For Explicit Control)

If you want to explicitly confirm you're fetching the full _source (in case your index has custom default settings), pair _source: true with the filter_path parameter:

POST /your_target_index/_search
{
  "_source": true,
  "filter_path": ["hits.hits._source"],
  "query": {
    "match": { "content": "elasticsearch tips" }
  }
}

Note: _source: true is Elasticsearch's default behavior, so this is optional—but it’s handy if you need to override any configurations that might hide the _source.

3. Skip the fields Parameter for This Use Case

While you could use fields to fetch all fields, it’s not ideal for getting the full _source. It returns a different structure (field names as keys with array values) instead of the original _source object. Stick to the first two methods for clean, direct results.

That’s all you need! Any of these approaches will give you exactly the _source content you want, without the extra noise.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.28 09:56:38