{"record":{"id":"f18af84b84c6c07a","repo":"spring-projects/spring-ai","slug":"index-not-found","errorCode":null,"errorMessage":"Index not found","messagePattern":"Index not found","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"vector-stores/spring-ai-elasticsearch-store/src/main/java/org/springframework/ai/vectorstore/elasticsearch/ElasticsearchVectorStore.java","lineNumber":363,"sourceCode":"\n\tprivate DenseVectorSimilarity parseSimilarity(String similarity) {\n\t\tfor (DenseVectorSimilarity sim : DenseVectorSimilarity.values()) {\n\t\t\tif (sim.jsonValue().equalsIgnoreCase(similarity)) {\n\t\t\t\treturn sim;\n\t\t\t}\n\t\t}\n\t\tthrow new IllegalArgumentException(\"Unsupported similarity: \" + similarity);\n\t}\n\n\t@Override\n\tpublic void afterPropertiesSet() {\n\t\t// For the index to be present, either it must be pre-created or set the\n\t\t// initializeSchema to true.\n\t\tif (indexExists()) {\n\t\t\treturn;\n\t\t}\n\t\tif (!this.initializeSchema) {\n\t\t\tthrow new IllegalArgumentException(\"Index not found\");\n\t\t}\n\t\tcreateIndexMapping();\n\t}\n\n\t@Override\n\tpublic VectorStoreObservationContext.Builder createObservationContextBuilder(String operationName) {\n\t\treturn VectorStoreObservationContext.builder(VectorStoreProvider.ELASTICSEARCH.value(), operationName)\n\t\t\t.collectionName(this.options.getIndexName())\n\t\t\t.dimensions(this.embeddingModel.dimensions())\n\t\t\t.similarityMetric(getSimilarityMetric());\n\t}\n\n\tprivate String getSimilarityMetric() {\n\t\tif (!SIMILARITY_TYPE_MAPPING.containsKey(this.options.getSimilarity())) {\n\t\t\treturn this.options.getSimilarity().name();\n\t\t}\n\t\treturn SIMILARITY_TYPE_MAPPING.get(this.options.getSimilarity()).value();\n\t}","sourceCodeStart":345,"sourceCodeEnd":381,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/vector-stores/spring-ai-elasticsearch-store/src/main/java/org/springframework/ai/vectorstore/elasticsearch/ElasticsearchVectorStore.java#L345-L381","documentation":"In ElasticsearchVectorStore.afterPropertiesSet, if the target index does not exist and initializeSchema is false, the store cannot create the mapping and throws IllegalArgumentException(\"Index not found\"). This is an explicit startup-time configuration guard: the library refuses to run against a non-existent index it is not allowed to create.","triggerScenarios":"Instantiating ElasticsearchVectorStore as a bean (afterPropertiesSet) where indexExists() is false and ElasticsearchVectorStoreOptions.initializeSchema was not set to true.","commonSituations":"Fresh environment with no pre-created index, initializeSchema property left at default false in application config, wrong index name configured, or connecting to a different Elasticsearch cluster than expected.","solutions":["Set initializeSchema=true (builder or property spring.ai.vectorstore.elasticsearch.initialize-schema) so the store creates the index","Pre-create the index with the correct dense_vector mapping manually","Verify options.getIndexName() points at an existing index in the configured cluster"],"exampleFix":"// before\nElasticsearchVectorStore store = ElasticsearchVectorStore.builder(elasticsearchClient, embeddingModel).build();\n// after\nElasticsearchVectorStore store = ElasticsearchVectorStore.builder(elasticsearchClient, embeddingModel)\n    .initializeSchema(true)\n    .build();","handlingStrategy":"validation","validationCode":"boolean exists = elasticsearchClient.indices().exists(e -> e.index(options.getIndexName())).value();\nif (!exists) {\n    // set initializeSchema(true) or create index before building the store\n}","typeGuard":null,"tryCatchPattern":"try {\n    vectorStore = ElasticsearchVectorStore.builder(client, embeddingModel).initializeSchema(true).build();\n} catch (IllegalArgumentException e) {\n    if (\"Index not found\".equals(e.getMessage())) {\n        throw new IllegalStateException(\"Pre-create the index or enable initializeSchema\", e);\n    }\n    throw e;\n}","preventionTips":["Set spring.ai.vectorstore.elasticsearch.initialize-schema=true in non-prod environments","Pre-create the index via a migration/template in production","Confirm indexName matches the cluster you connect to"],"tags":["elasticsearch","vector-store","index","configuration","startup"],"backgroundTag":"resource-not-found","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}