--- title: "索引不存在且自动创建索引设置被禁用 - 如何解决此 Elasticsearch 异常" date: 2026-02-28 lastmod: 2026-02-28 description: "当 Elasticsearch 尝试自动创建不存在的索引,但自动创建索引设置被禁用或受限时,会出现此错误。本文介绍解决方案。" tags: ["索引管理", "自动创建索引", "配置设置"] summary: "版本: 6.8-6.8 简而言之,当 Elasticsearch 尝试自动创建不存在的索引,但自动创建索引设置被禁用或受限时,会出现此错误。该设置可以配置为允许或禁止自动创建索引。要解决此问题,您可以将自动创建索引设置设置为 true 来启用它,或者在索引文档之前手动创建索引。此外,您还可以调整自动创建索引设置以允许特定索引自动创建。 日志上下文 # 日志 “no such index and [” + AUTO_CREATE_INDEX_SETTING.getKey() + “] contains [-” 类名是 AutoCreateIndex.java. 我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入上下文的人参考: boolean include = expression.v2(); if (Regex.simpleMatch(indexExpression, index)) { if (include) { return true; } throw new IndexNotFoundException("no such index and [" + AUTO_CREATE_INDEX_SETTING.getKey() + "] contains [-" + indexExpression + "] which forbids automatic creation of the index"; index); } } throw new IndexNotFoundException("no such index and [" + AUTO_CREATE_INDEX_SETTING." --- > **版本:** 6.8-6.8 简而言之,当 Elasticsearch 尝试自动创建不存在的索引,但自动创建索引设置被禁用或受限时,会出现此错误。该设置可以配置为允许或禁止自动创建索引。要解决此问题,您可以将自动创建索引设置设置为 true 来启用它,或者在索引文档之前手动创建索引。此外,您还可以调整自动创建索引设置以允许特定索引自动创建。 日志上下文 ----------- 日志 "no such index and [" + AUTO\_CREATE\_INDEX\_SETTING.getKey() + "] contains [-" 类名是 [AutoCreateIndex.java.](https://www.geeksforgeeks.org/java-lang-class-class-java-set-1/) 我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入上下文的人参考: ```java boolean include = expression.v2(); if (Regex.simpleMatch(indexExpression, index)) { if (include) { return true; } throw new IndexNotFoundException("no such index and [" + AUTO_CREATE_INDEX_SETTING.getKey() + "] contains [-" + indexExpression + "] which forbids automatic creation of the index"; index); } } throw new IndexNotFoundException("no such index and [" + AUTO_CREATE_INDEX_SETTING.getKey() + "] ([" + autoCreate + "]) doesn't match"; index); ```