--- title: "尝试向不存在的索引添加映射 - 如何解决此 Elasticsearch 异常" date: 2026-02-03 lastmod: 2026-02-03 description: "当向Elasticsearch中不存在的索引添加映射时出现错误,需要先创建索引或使用索引模板" tags: ["映射管理", "索引配置", "索引模板"] summary: " 版本: 6.8-7.15 简而言之,当您尝试向 Elasticsearch 中不存在的索引更新或添加映射时,会出现此错误。Elasticsearch 要求在添加映射之前必须先存在索引。要解决此问题,您可以在添加映射之前先创建索引,或者使用索引模板。索引模板会自动将映射应用于匹配模板模式的新索引。此外,您还可以使用"创建索引" API,并在请求中包含映射定义。 日志上下文 # 日志"Attempt to put missing mapping in indices"的类名是 ElasticsearchMappings.java。我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入上下文的人参考: executeAsyncWithOrigin(client; ML_ORIGIN; PutMappingAction.INSTANCE; putMappingRequest; ActionListener.wrap(response -> { if (response.isAcknowledged()) { listener.onResponse(true); } else { listener.onFailure(new ElasticsearchException("Attempt to put missing mapping in indices " + Arrays.toString(indicesThatRequireAnUpdate) + " was not acknowledged")); } }; listener::onFailure)); } catch (IOException e) { listener.onFailure(e); " --- > **版本:** 6.8-7.15 简而言之,当您尝试向 Elasticsearch 中不存在的索引更新或添加映射时,会出现此错误。Elasticsearch 要求在添加映射之前必须先存在索引。要解决此问题,您可以在添加映射之前先创建索引,或者使用索引模板。索引模板会自动将映射应用于匹配模板模式的新索引。此外,您还可以使用"创建索引" API,并在请求中包含映射定义。 日志上下文 ----------- 日志"Attempt to put missing mapping in indices"的类名是 [ElasticsearchMappings.java](https://www.geeksforgeeks.org/java-lang-class-class-java-set-1/)。我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入上下文的人参考: ```java executeAsyncWithOrigin(client; ML_ORIGIN; PutMappingAction.INSTANCE; putMappingRequest; ActionListener.wrap(response -> { if (response.isAcknowledged()) { listener.onResponse(true); } else { listener.onFailure(new ElasticsearchException("Attempt to put missing mapping in indices " + Arrays.toString(indicesThatRequireAnUpdate) + " was not acknowledged")); } }; listener::onFailure)); } catch (IOException e) { listener.onFailure(e); ```