spring-projects/spring-ai · error · IllegalArgumentException
Index not found
Error message
Index not found
What it means
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.
Source
Thrown at vector-stores/spring-ai-elasticsearch-store/src/main/java/org/springframework/ai/vectorstore/elasticsearch/ElasticsearchVectorStore.java:363
private DenseVectorSimilarity parseSimilarity(String similarity) {
for (DenseVectorSimilarity sim : DenseVectorSimilarity.values()) {
if (sim.jsonValue().equalsIgnoreCase(similarity)) {
return sim;
}
}
throw new IllegalArgumentException("Unsupported similarity: " + similarity);
}
@Override
public void afterPropertiesSet() {
// For the index to be present, either it must be pre-created or set the
// initializeSchema to true.
if (indexExists()) {
return;
}
if (!this.initializeSchema) {
throw new IllegalArgumentException("Index not found");
}
createIndexMapping();
}
@Override
public VectorStoreObservationContext.Builder createObservationContextBuilder(String operationName) {
return VectorStoreObservationContext.builder(VectorStoreProvider.ELASTICSEARCH.value(), operationName)
.collectionName(this.options.getIndexName())
.dimensions(this.embeddingModel.dimensions())
.similarityMetric(getSimilarityMetric());
}
private String getSimilarityMetric() {
if (!SIMILARITY_TYPE_MAPPING.containsKey(this.options.getSimilarity())) {
return this.options.getSimilarity().name();
}
return SIMILARITY_TYPE_MAPPING.get(this.options.getSimilarity()).value();
}View on GitHub (pinned to 98a7beda4f)
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
Example fix
// before
ElasticsearchVectorStore store = ElasticsearchVectorStore.builder(elasticsearchClient, embeddingModel).build();
// after
ElasticsearchVectorStore store = ElasticsearchVectorStore.builder(elasticsearchClient, embeddingModel)
.initializeSchema(true)
.build(); Defensive patterns
Strategy: validation
Validate before calling
boolean exists = elasticsearchClient.indices().exists(e -> e.index(options.getIndexName())).value();
if (!exists) {
// set initializeSchema(true) or create index before building the store
} Try / catch
try {
vectorStore = ElasticsearchVectorStore.builder(client, embeddingModel).initializeSchema(true).build();
} catch (IllegalArgumentException e) {
if ("Index not found".equals(e.getMessage())) {
throw new IllegalStateException("Pre-create the index or enable initializeSchema", e);
}
throw e;
} Prevention
- 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
When it happens
Trigger: Instantiating ElasticsearchVectorStore as a bean (afterPropertiesSet) where indexExists() is false and ElasticsearchVectorStoreOptions.initializeSchema was not set to true.
Common situations: 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.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Unsupported similarity: {similarity}
- SSE connection '<connectionName>' requires a 'url' property.
- Found 2 elicitation handlers for client [%s], found in bean
- Found 2 sampling handlers for client [%s], found in bean wit
- Index %s does not exist in table %s
AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11).
Data as JSON: /api/errors/f18af84b84c6c07a.
Report an issue: GitHub.