{"record":{"id":"9b775d1bd6849f6c","repo":"spring-projects/spring-ai","slug":"failed-to-create-index","errorCode":null,"errorMessage":"Failed to create index: ","messagePattern":"Failed to create index: ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"memory-repositories/spring-ai-model-chat-memory-repository-redis/src/main/java/org/springframework/ai/chat/memory/repository/redis/RedisChatMemoryRepository.java","lineNumber":443,"sourceCode":"\t\t\t\t\t// When specific metadata fields are defined, we don't add a wildcard\n\t\t\t\t\t// metadata field to avoid indexing errors with non-string values\n\t\t\t\t}\n\n\t\t\t\telse {\n\t\t\t\t\t// No schema provided - fallback to indexing all metadata as text\n\t\t\t\t\tschemaFields.add(new TextField(\"$.metadata.*\").as(\"metadata\"));\n\t\t\t\t}\n\n\t\t\t\t// Create the index with the defined schema\n\t\t\t\tFTCreateParams indexParams = FTCreateParams.createParams()\n\t\t\t\t\t.on(IndexDataType.JSON)\n\t\t\t\t\t.prefix(this.config.getKeyPrefix());\n\n\t\t\t\tString response = this.jedisClient.ftCreate(this.config.getIndexName(), indexParams,\n\t\t\t\t\t\tschemaFields.toArray(new SchemaField[0]));\n\n\t\t\t\tif (!response.equals(\"OK\")) {\n\t\t\t\t\tthrow new IllegalStateException(\"Failed to create index: \" + response);\n\t\t\t\t}\n\n\t\t\t\tif (logger.isDebugEnabled()) {\n\t\t\t\t\tlogger.debug(\"Created Redis search index '\" + this.config.getIndexName() + \"' with \"\n\t\t\t\t\t\t\t+ schemaFields.size() + \" schema fields\");\n\t\t\t\t}\n\t\t\t}\n\n\t\t\telse if (logger.isDebugEnabled()) {\n\t\t\t\tlogger.debug(\"Redis search index '\" + this.config.getIndexName() + \"' already exists\");\n\t\t\t}\n\t\t}\n\n\t\tcatch (Exception e) {\n\t\t\tif (logger.isErrorEnabled()) {\n\t\t\t\tlogger.error(\"Failed to initialize Redis schema: \" + e.getMessage());\n\t\t\t}\n\t\t\tlogger.debug(\"Error details\", e);","sourceCodeStart":425,"sourceCodeEnd":461,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/memory-repositories/spring-ai-model-chat-memory-repository-redis/src/main/java/org/springframework/ai/chat/memory/repository/redis/RedisChatMemoryRepository.java#L425-L461","documentation":"RedisChatMemoryRepository.initializeSchema() creates a RediSearch index via jedisClient.ftCreate(). If the server response is not \"OK\" the repository throws IllegalStateException including the raw response. This usually means the index could not be created (name conflict with different parameters, unsupported schema, or a Redis module issue).","triggerScenarios":"Repository construction triggering schema init against a Redis instance where ftCreate fails — e.g. an existing index with the same name but a different schema, or a misbehaving RediSearch module.","commonSituations":"Index already exists from an earlier run with a different schema; connecting to plain Redis without the RediSearch module; restricted/managed Redis disallowing FT.CREATE.","solutions":["Check the response string in the message for the RediSearch error detail","Drop the stale index (FT.DROPINDEX <indexName>) and restart so it is recreated with the current schema","Verify the Redis server has the RediSearch module loaded (FT.INFO <indexName>)","Ensure the configured indexName doesn't collide with an index of a different schema"],"exampleFix":"// before\nredis-cli> FT.INFO chat-memory-index  // schema mismatch\n// after\nredis-cli> FT.DROPINDEX chat-memory-index\n// then restart the app to recreate the index","handlingStrategy":"try-catch","validationCode":"// before constructing, confirm the index name and RediSearch availability\nString info = jedis.ftInfo(indexName); // catch unknown-index and check module support","typeGuard":null,"tryCatchPattern":"try { repo = RedisChatMemoryRepository.builder()...build(); }\ncatch (IllegalStateException e) {\n    if (e.getMessage().startsWith(\"Failed to create index\")) { /* drop and recreate index or alert */ }\n    throw e;\n}","preventionTips":["Drop stale indexes after changing the schema definition","Verify RediSearch is loaded before deploying (MODULE LIST)","Use a unique indexName per deployment/schema version"],"tags":["redis","redisearch","index-creation","schema"],"backgroundTag":"database-write-failed","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}