{"record":{"id":"b97c59e8619462cf","repo":"alibaba/spring-ai-alibaba","slug":"elastic-search-index-name-must-be-provided","errorCode":null,"errorMessage":"Elastic search index name must be provided","messagePattern":"Elastic search index name must be provided","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/rag/vectorstore/elasticsearch/ElasticSearchVectorStoreService.java","lineNumber":103,"sourceCode":"\tprivate final FilterExpressionConverter filterExpressionConverter = new ElasticsearchAiSearchFilterExpressionConverter();\n\n\tpublic ElasticSearchVectorStoreService(ModelFactory modelFactory, ElasticsearchClient elasticsearchClient,\n\t\t\tRestClient restClient) {\n\t\tthis.modelFactory = modelFactory;\n\t\tthis.elasticsearchClient = elasticsearchClient;\n\t\tthis.restClient = restClient;\n\t}\n\n\t/**\n\t * Creates a new Elasticsearch index with vector search capabilities\n\t * @param indexConfig Configuration for the index including name and embedding model\n\t */\n\t@Override\n\tpublic void createIndex(IndexConfig indexConfig) {\n\t\tString indexName = indexConfig.getName();\n\n\t\tif (StringUtils.isBlank(indexName)) {\n\t\t\tthrow new IllegalArgumentException(\"Elastic search index name must be provided\");\n\t\t}\n\n\t\tElasticsearchVectorStoreOptions options = new ElasticsearchVectorStoreOptions();\n\t\toptions.setIndexName(indexName);\n\t\toptions.setSimilarity(SimilarityFunction.dot_product);\n\n\t\tString similarityAlgo = SimilarityFunction.cosine.name();\n\t\tIndexSettings indexSettings = IndexSettings\n\t\t\t.of(settings -> settings.numberOfShards(String.valueOf(1)).numberOfReplicas(String.valueOf(1)));\n\n\t\t// Maybe using json directly?\n\t\tint dimension = EmbeddingModelDimension.getDimension(indexConfig.getEmbeddingModel(), DEFAULT_DIMENSION);\n\t\tMap<String, Property> properties = new HashMap<>();\n\t\tproperties.put(RagConstants.VECTOR_FIELD, Property.of(property -> property.denseVector(\n\t\t\t\tDenseVectorProperty.of(dense -> dense.index(true).dims(dimension).similarity(similarityAlgo)))));\n\t\tproperties.put(RagConstants.TEXT_FIELD, Property.of(property -> property.text(TextProperty.of(t -> t))));\n\n\t\tMap<String, Property> metadata = new HashMap<>();","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/rag/vectorstore/elasticsearch/ElasticSearchVectorStoreService.java#L85-L121","documentation":"ElasticSearchVectorStoreService.createIndex() requires a non-blank index name from the supplied IndexConfig; if name is null/empty/whitespace it throws IllegalArgumentException before any Elasticsearch call is made. This is a fail-fast required-argument check.","triggerScenarios":"Calling createIndex() with an IndexConfig whose name was never set, or set to \"\" or \" \".","commonSituations":"Building IndexConfig programmatically and forgetting setName(); reading a knowledge-base name from config/DB that is empty; trimming user input down to nothing.","solutions":["Set a valid index name: indexConfig.setName(\"kb-...\") before calling createIndex","Validate the name with StringUtils.isBlank at the caller before invoking createIndex","Ensure the knowledge base record supplying the name is populated and not blank"],"exampleFix":"// before\nIndexConfig cfg = new IndexConfig();\nstore.createIndex(cfg);\n// after\nIndexConfig cfg = new IndexConfig();\ncfg.setName(\"my-knowledge-base\");\nif (StringUtils.isBlank(cfg.getName())) throw new IllegalStateException(\"index name required\");\nstore.createIndex(cfg);","handlingStrategy":"validation","validationCode":"if (indexConfig == null || StringUtils.isBlank(indexConfig.getName())) {\n    throw new IllegalArgumentException(\"createIndex requires a non-blank index name\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    store.createIndex(indexConfig);\n} catch (IllegalArgumentException e) {\n    log.error(\"Index config invalid: {}\", e.getMessage());\n}","preventionTips":["Always setName() on IndexConfig at construction","Validate knowledge-base names before persistence","Use a builder/factory that enforces a non-blank name"],"tags":["elasticsearch","validation","rag","java"],"backgroundTag":"missing-required-argument","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}