--- title: "字段名不能设置为 index = false – 如何解决此 Elasticsearch 异常" date: 2026-02-18 lastmod: 2026-02-18 description: "当 Elasticsearch 中的字段设置为 index = false 时会报错,这意味着该字段不可搜索且不能在查询中使用。本文介绍了解决此问题的多种方法。" tags: ["映射异常", "字段索引", "通配符字段"] summary: " 版本: 7.9-7.1 简而言之,当 Elasticsearch 中的字段设置为"index = false"时,会发生此错误。这意味着该字段不可搜索且不能在查询中使用。要解决此问题,您可以将字段的映射更改为"index = true",这将使其可搜索。或者,如果该字段不需要用于搜索,您可以从查询中删除它。另一个解决方案是在查询中使用"_source"字段,无论其"index"设置如何,它都包含所有字段。 日志上下文 # 日志"The field [" + name + “] cannot have index = false"的类名是 WildcardFieldMapper.java. 我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入背景的人参考: } @Override public Builder index(boolean index) { if (index == false) { throw new MapperParsingException("The field [" + name + "] cannot have index = false"); } return this; } public Builder nullValue(String nullValue) { " --- > **版本:** 7.9-7.1 简而言之,当 Elasticsearch 中的字段设置为"index = false"时,会发生此错误。这意味着该字段不可搜索且不能在查询中使用。要解决此问题,您可以将字段的映射更改为"index = true",这将使其可搜索。或者,如果该字段不需要用于搜索,您可以从查询中删除它。另一个解决方案是在查询中使用"_source"字段,无论其"index"设置如何,它都包含所有字段。 日志上下文 ----------- 日志"The field [" + name + "] cannot have index = false"的类名是 [WildcardFieldMapper.java.](https://www.geeksforgeeks.org/java-lang-class-class-java-set-1/) 我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入背景的人参考: ```java } @Override public Builder index(boolean index) { if (index == false) { throw new MapperParsingException("The field [" + name + "] cannot have index = false"); } return this; } public Builder nullValue(String nullValue) { ```