{"record":{"id":"58e2ad4e18d72a3e","repo":"alibaba/spring-ai-alibaba","slug":"index-not-found","errorCode":null,"errorMessage":"Index not found","messagePattern":"Index not found","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/org/springframework/ai/vectorstore/elasticsearch/ElasticsearchVectorStore.java","lineNumber":187,"sourceCode":"\t\tAssert.notNull(builder.restClient, \"RestClient must not be null\");\n\n\t\tthis.initializeSchema = builder.initializeSchema;\n\t\tthis.options = builder.options;\n\t\tthis.filterExpressionConverter = builder.filterExpressionConverter;\n\n\t\tString version = Version.VERSION == null ? \"Unknown\" : Version.VERSION.toString();\n\t\tthis.elasticsearchClient = new ElasticsearchClient(new RestClientTransport(builder.restClient,\n\t\t\t\tnew JacksonJsonpMapper(\n\t\t\t\t\t\tnew ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false))))\n\t\t\t.withTransportOptions(t -> t.addHeader(\"user-agent\", \"spring-ai elastic-java/\" + version));\n\t}\n\n\t@Override\n\tpublic void doAdd(List<Document> documents) {\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\tthrow new IllegalArgumentException(\"Index not found\");\n\t\t}\n\t\tBulkRequest.Builder bulkRequestBuilder = new BulkRequest.Builder();\n\n\t\tList<float[]> embeddings = this.embeddingModel.embed(documents,  EmbeddingOptions.builder().build(),\n\t\t\t\tthis.batchingStrategy);\n\n\t\tfor (Document document : documents) {\n\t\t\tElasticSearchDocument doc = new ElasticSearchDocument(document.getId(), document.getText(),\n\t\t\t\t\tdocument.getMetadata(), embeddings.get(documents.indexOf(document)));\n\t\t\tbulkRequestBuilder.operations(\n\t\t\t\t\top -> op.index(idx -> idx.index(this.options.getIndexName()).id(document.getId()).document(doc)));\n\t\t}\n\t\tBulkResponse bulkRequest = bulkRequest(bulkRequestBuilder.build());\n\t\tif (bulkRequest.errors()) {\n\t\t\tList<BulkResponseItem> bulkResponseItems = bulkRequest.items();\n\t\t\tfor (BulkResponseItem bulkResponseItem : bulkResponseItems) {\n\t\t\t\tif (bulkResponseItem.error() != null) {\n\t\t\t\t\tthrow new IllegalStateException(bulkResponseItem.error().reason());","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/org/springframework/ai/vectorstore/elasticsearch/ElasticsearchVectorStore.java#L169-L205","documentation":"ElasticsearchVectorStore.doAdd refuses to write documents unless the target index already exists in Elasticsearch. The index must be pre-created or the store must have been built with initializeSchema=true, which creates the index during initialization.","triggerScenarios":"Calling VectorStore.add(documents) (which invokes doAdd) when the configured index (options.getIndexName()) does not exist because initializeSchema was false and nobody created the index.","commonSituations":"Fresh Elasticsearch cluster or changed index name in options; initialize-schema property left at default false in Spring Boot config; index deleted by ILM/retention policies or manual cleanup.","solutions":["Set initializeSchema(true) when building the ElasticsearchVectorStore so the index is created automatically.","Pre-create the index with an appropriate mapping before adding documents.","Verify the index name in options matches an existing index (GET /_cat/indices).","Check Elasticsearch connectivity/permissions — indexExists() may report false if the client cannot reach the cluster."],"exampleFix":"// before\nElasticsearchVectorStore store = ElasticsearchVectorStore.builder(elasticsearchClient, embeddingModel)\n    .options(ElasticsearchVectorStoreOptions.options().indexName(\"docs\"))\n    .build();\n// after\nElasticsearchVectorStore store = ElasticsearchVectorStore.builder(elasticsearchClient, embeddingModel)\n    .options(ElasticsearchVectorStoreOptions.options().indexName(\"docs\"))\n    .initializeSchema(true)\n    .build();","handlingStrategy":"validation","validationCode":"// Java: check index presence before adding\nboolean request = new ExistsRequest.Builder().index(indexName).build();\nboolean exists = elasticsearchClient.cluster().state(...).toString().contains(indexName); // or client.indices().exists(r -> r.index(indexName)).value();\nif (!exists) { elasticsearchClient.indices().create(c -> c.index(indexName)); }","typeGuard":null,"tryCatchPattern":"try { vectorStore.add(docs); } catch (IllegalArgumentException e) {\n    if (\"Index not found\".equals(e.getMessage())) { elasticsearchClient.indices().create(c -> c.index(indexName)); vectorStore.add(docs); }\n    else throw e;\n}","preventionTips":["Always set initializeSchema(true) in non-production-locked environments.","Provision index templates/mappings via IaC before app startup.","Pin and verify the index name in one shared config constant.","Add a startup health check that asserts the index exists."],"tags":["elasticsearch","vector-store","index"],"backgroundTag":"resource-not-found","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}