--- title: "只能在keyword、text和wildcard字段上使用前缀查询,而不能在其他字段上使用 - 如何解决此Elasticsearch异常" date: 2026-01-15 lastmod: 2026-01-15 description: "当您尝试在不支持前缀查询的字段类型上使用前缀查询时,会出现此错误。Elasticsearch只允许在keyword、text和wildcard字段上使用前缀查询。" tags: ["Elasticsearch", "前缀查询", "字段类型", "查询异常", "MappedFieldType"] summary: " 版本: 7.9-7.15 简而言之,当您尝试在不支持前缀查询的字段类型上使用前缀查询时,会出现此错误。Elasticsearch只允许在keyword、text和wildcard字段上使用前缀查询。如果您尝试在数字或日期等其他字段类型上使用前缀查询,将会遇到此错误。要解决此问题,您可以将字段类型更改为支持前缀查询的类型,或者使用与当前字段类型兼容的其他查询类型。 日志上下文 # 日志"只能在keyword、text和wildcard字段上使用前缀查询 - 而不能在 [“的类名是 MappedFieldType.java。我们从Elasticsearch源代码中提取了以下内容,供那些寻求深入上下文的人参考: return prefixQuery(value; method; false; context); } public Query prefixQuery(String value; @Nullable MultiTermQuery.RewriteMethod method; boolean caseInsensitve; SearchExecutionContext context) { throw new QueryShardException(context; "Can only use prefix queries on keyword; text and wildcard fields - not on [" + name + "] which is of type [" + typeName() + "]"); } // Case sensitive form of wildcard query public final Query wildcardQuery(String value; " --- > **版本:** 7.9-7.15 简而言之,当您尝试在不支持前缀查询的字段类型上使用前缀查询时,会出现此错误。Elasticsearch只允许在keyword、text和wildcard字段上使用前缀查询。如果您尝试在数字或日期等其他字段类型上使用前缀查询,将会遇到此错误。要解决此问题,您可以将字段类型更改为支持前缀查询的类型,或者使用与当前字段类型兼容的其他查询类型。 日志上下文 ----------- 日志"只能在keyword、text和wildcard字段上使用前缀查询 - 而不能在 ["的类名是[MappedFieldType.java](https://www.geeksforgeeks.org/java-lang-class-class-java-set-1/)。我们从Elasticsearch源代码中提取了以下内容,供那些寻求深入上下文的人参考: ```java return prefixQuery(value; method; false; context); } public Query prefixQuery(String value; @Nullable MultiTermQuery.RewriteMethod method; boolean caseInsensitve; SearchExecutionContext context) { throw new QueryShardException(context; "Can only use prefix queries on keyword; text and wildcard fields - not on [" + name + "] which is of type [" + typeName() + "]"); } // Case sensitive form of wildcard query public final Query wildcardQuery(String value; ```