--- title: "运行时字段设置为null但不支持删除 – 如何解决此Elasticsearch异常" date: 2026-02-02 lastmod: 2026-02-02 description: "当尝试在Elasticsearch中将运行时字段设置为null时会报错,因为运行时字段设计为始终存在,不能被删除或设置为null。" tags: ["运行时字段", "字段映射", "空值处理"] summary: "版本: 7.12-7.15 简而言之,当您尝试在Elasticsearch中将运行时字段设置为null时会发生此错误,这是不支持的。运行时字段被设计为始终存在,不能被删除或设置为null。要解决此问题,您可以将字段的值更改为null以外的值,或者使用支持null值的其他字段类型。或者,您可以使用脚本以适合应用程序需求的方式处理null值。 日志上下文 # 日志 “Runtime field [” + fieldName + “] was set to null but its removal is not supported " 的类名是 RuntimeField.java. 我们从Elasticsearch源代码中提取了以下内容,供那些寻求深入了解上下文的人参考: String fieldName = entry.getKey(); if (entry.getValue() == null) { if (supportsRemoval) { runtimeFields.put(fieldName; null); } else { throw new MapperParsingException("Runtime field [" + fieldName + "] was set to null but its removal is not supported " + "in this context"); } } else if (entry." --- > **版本:** 7.12-7.15 简而言之,当您尝试在Elasticsearch中将运行时字段设置为null时会发生此错误,这是不支持的。运行时字段被设计为始终存在,不能被删除或设置为null。要解决此问题,您可以将字段的值更改为null以外的值,或者使用支持null值的其他字段类型。或者,您可以使用脚本以适合应用程序需求的方式处理null值。 日志上下文 ----------- 日志 "Runtime field [" + fieldName + "] was set to null but its removal is not supported " 的类名是 [RuntimeField.java.](https://www.geeksforgeeks.org/java-lang-class-class-java-set-1/) 我们从Elasticsearch源代码中提取了以下内容,供那些寻求深入了解上下文的人参考: ```java String fieldName = entry.getKey(); if (entry.getValue() == null) { if (supportsRemoval) { runtimeFields.put(fieldName; null); } else { throw new MapperParsingException("Runtime field [" + fieldName + "] was set to null but its removal is not supported " + "in this context"); } } else if (entry.getValue() instanceof Map) { @SuppressWarnings("unchecked") MappropNode = new HashMap<>(((Map) entry.getValue())); ```