--- title: "不能包含以下字符 - 如何解决此 Elasticsearch 异常" date: 2026-01-27 lastmod: 2026-01-27 description: "当 Elasticsearch 在索引名称、文档 ID 或字段名中遇到禁止字符时,会引发此错误。本文介绍如何解决此异常。" tags: ["索引管理", "异常处理", "字符限制", "仓库"] summary: " 版本: 7.14-8.9 简而言之,当 Elasticsearch 在索引名称、文档 ID 或字段名中遇到禁止字符时,就会发生此错误。Elasticsearch 对这些标识符中允许使用的字符有一组限制。错误消息通常会指出是哪些字符导致了问题。要解决此问题,您应该重命名索引、文档 ID 或字段名,以排除这些字符。如果禁止字符是自动生成的,您可能需要修改数据摄取或处理脚本,以防止包含这些字符。 日志上下文 # 日志"must not contain the following characters"的类名是 RepositoriesService.java。我们从Elasticsearch源代码中提取了以下内容,供那些寻求深入上下文的人参考: } if (repositoryName.contains("#")) { throw new RepositoryException(repositoryName; "must not contain '#'"); } if (Strings.validFileName(repositoryName) == false) { throw new RepositoryException(repositoryName; "must not contain the following characters " + Strings.INVALID_FILENAME_CHARS); } } private static void ensureRepositoryNotInUse(ClusterState clusterState; String repository) { final SnapshotsInProgress snapshots = clusterState.custom(SnapshotsInProgress.TYPE; SnapshotsInProgress.EMPTY); " --- > **版本:** 7.14-8.9 简而言之,当 Elasticsearch 在索引名称、文档 ID 或字段名中遇到禁止字符时,就会发生此错误。Elasticsearch 对这些标识符中允许使用的字符有一组限制。错误消息通常会指出是哪些字符导致了问题。要解决此问题,您应该重命名索引、文档 ID 或字段名,以排除这些字符。如果禁止字符是自动生成的,您可能需要修改数据摄取或处理脚本,以防止包含这些字符。 日志上下文 ----------- 日志"must not contain the following characters"的类名是[RepositoriesService.java。](https://www.geeksforgeeks.org/java-lang-class-class-java-set-1/)我们从Elasticsearch源代码中提取了以下内容,供那些寻求深入上下文的人参考: ```java } if (repositoryName.contains("#")) { throw new RepositoryException(repositoryName; "must not contain '#'"); } if (Strings.validFileName(repositoryName) == false) { throw new RepositoryException(repositoryName; "must not contain the following characters " + Strings.INVALID_FILENAME_CHARS); } } private static void ensureRepositoryNotInUse(ClusterState clusterState; String repository) { final SnapshotsInProgress snapshots = clusterState.custom(SnapshotsInProgress.TYPE; SnapshotsInProgress.EMPTY); ```