--- title: "source字段不可搜索——如何解决此Elasticsearch异常" date: 2026-03-21 lastmod: 2026-03-21 description: "当在Elasticsearch中尝试使用_source字段进行搜索时会触发此错误。_source字段是包含已索引原始JSON文档的特殊字段,但不可搜索。" tags: ["source字段", "搜索异常", "字段映射", "查询错误"] summary: " 版本: 6.8-8.9 简而言之,当您尝试在Elasticsearch中使用_source字段进行搜索时会发生此错误。_source字段是一个特殊的字段,包含已索引的原始JSON文档,但它不可搜索。要解决此问题,您可以使用_source字段中的字段进行搜索,或者在映射中为特定字段启用"store"选项,使其可搜索。或者,您可以使用脚本字段从_source字段中提取并返回所需的数据。 日志上下文 # 日志"The _source field is not searchable"的类名是 SourceFieldMapper.java。我们从Elasticsearch源代码中提取了以下内容,供寻求深入背景的人参考: throw new UnsupportedOperationException("Cannot fetch values for internal field [" + name() + "]."); } @Override public Query existsQuery(SearchExecutionContext context) { throw new QueryShardException(context; "The _source field is not searchable"); } @Override public Query termQuery(Object value; SearchExecutionContext context) { throw new QueryShardException(context; "The _source field is not searchable"); " --- > **版本:** 6.8-8.9 简而言之,当您尝试在Elasticsearch中使用_source字段进行搜索时会发生此错误。_source字段是一个特殊的字段,包含已索引的原始JSON文档,但它不可搜索。要解决此问题,您可以使用_source字段中的字段进行搜索,或者在映射中为特定字段启用"store"选项,使其可搜索。或者,您可以使用脚本字段从_source字段中提取并返回所需的数据。 日志上下文 ----------- 日志"The _source field is not searchable"的类名是[SourceFieldMapper.java](https://www.geeksforgeeks.org/java-lang-class-class-java-set-1/)。我们从Elasticsearch源代码中提取了以下内容,供寻求深入背景的人参考: ```java throw new UnsupportedOperationException("Cannot fetch values for internal field [" + name() + "]."); } @Override public Query existsQuery(SearchExecutionContext context) { throw new QueryShardException(context; "The _source field is not searchable"); } @Override public Query termQuery(Object value; SearchExecutionContext context) { throw new QueryShardException(context; "The _source field is not searchable"); ```