--- title: "数值字段必须同时设置这两个参数 - 如何解决此 Elasticsearch 异常" date: 2026-01-07 lastmod: 2026-01-07 description: "当Elasticsearch尝试索引缺少值或类型的数值字段的文档时,会抛出此异常。" tags: ["Elasticsearch异常", "数值字段", "衰减函数", "索引错误", "查询参数"] summary: " 版本: 6.8-7.15 简而言之,当 Elasticsearch 尝试索引一个缺少值或类型的数值字段的文档时,就会出现此错误。Elasticsearch 需要这两个参数才能正确索引和搜索数值字段。要解决此问题,请确保文档中的所有数值字段都具有值和类型。如果您是动态创建文档,请在代码中添加检查以确保始终设置这些字段。或者,您可以在 Elasticsearch 映射中为这些字段设置默认值。 日志上下文 # 日志 “both [{}] and [{}] must be set for numeric fields.” 的类名是 DecayFunctionBuilder.java。我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入上下文的人参考: } else { throw new ElasticsearchParseException("parameter [{}] not supported!"; parameterName); } } if (scaleFound == false || refFound == false) { throw new ElasticsearchParseException("both [{}] and [{}] must be set for numeric fields."; DecayFunctionBuilder.SCALE; DecayFunctionBuilder.ORIGIN); } IndexNumericFieldData numericFieldData = context.getForField(fieldType); return new NumericFieldDataScoreFunction(origin; scale; decay; offset; getDecayFunction(); numericFieldData; mode); } " --- > **版本:** 6.8-7.15 简而言之,当 Elasticsearch 尝试索引一个缺少值或类型的数值字段的文档时,就会出现此错误。Elasticsearch 需要这两个参数才能正确索引和搜索数值字段。要解决此问题,请确保文档中的所有数值字段都具有值和类型。如果您是动态创建文档,请在代码中添加检查以确保始终设置这些字段。或者,您可以在 Elasticsearch 映射中为这些字段设置默认值。 ## 日志上下文 日志 "both [{}] and [{}] must be set for numeric fields." 的类名是 [DecayFunctionBuilder.java](https://www.geeksforgeeks.org/java-lang-class-class-java-set-1/)。我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入上下文的人参考: ```java } else { throw new ElasticsearchParseException("parameter [{}] not supported!"; parameterName); } } if (scaleFound == false || refFound == false) { throw new ElasticsearchParseException("both [{}] and [{}] must be set for numeric fields."; DecayFunctionBuilder.SCALE; DecayFunctionBuilder.ORIGIN); } IndexNumericFieldData numericFieldData = context.getForField(fieldType); return new NumericFieldDataScoreFunction(origin; scale; decay; offset; getDecayFunction(); numericFieldData; mode); } ```