版本: 6.8-7.8
简而言之,当在不支持前缀查询的字段类型上使用前缀查询时,会出现此错误。Elasticsearch 只支持在关键字(keyword)和文本(text)字段上使用前缀查询。如果您尝试在数字、日期或其他非字符串字段上使用前缀查询,就会遇到此错误。
要解决此问题,您可以:
- 如果可能,将字段类型更改为 keyword 或 text
- 使用与当前字段类型兼容的其他查询类型
- 为查询目的创建 keyword 或 text 子字段
日志上下文 #
日志"Can only use prefix queries on keyword and text fields – not on [“的类名是 MappedFieldType.java。我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入理解的人参考:
throw new IllegalArgumentException("Can only use fuzzy queries on keyword and text fields - not on [" + name
+ "] which is of type [" + typeName() + "]");
} public Query prefixQuery(String value; @Nullable MultiTermQuery.RewriteMethod method; QueryShardContext context) {
throw new QueryShardException(context; "Can only use prefix queries on keyword and text fields - not on [" + name
+ "] which is of type [" + typeName() + "]");
} public Query wildcardQuery(String value;
@Nullable MultiTermQuery.RewriteMethod method;





