版本: 7.13-8.9
简要来说,当您尝试在一个未索引且未启用 doc_values 的字段上定义脚本时,会出现此错误。Elasticsearch 要求字段必须被索引或启用 doc_values 才能执行排序、聚合或脚本等操作。要解决此问题,您可以设置 “index: true” 使字段可搜索,或设置 “doc_values: true” 启用面向列的磁盘存储,这对排序和聚合很有用。请注意,更改这些设置需要重新索引数据。
日志上下文 #
日志 “Cannot define script on field with index:false and doc_values:false” 的类名是 FieldMapper.java。 我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入上下文的人参考:
ParameterindexParam;
ParameterdocValuesParam
) {
scriptParam.addValidator(s -> {
if (s != null && indexParam.get() == false && docValuesParam.get() == false) {
throw new MapperParsingException("Cannot define script on field with index:false and doc_values:false");
}
if (s != null && multiFieldsBuilder.hasMultiFields()) {
throw new MapperParsingException("Cannot define multifields on a field with a script");
}
if (s != null && copyTo.hasValues()) {





