{"record":{"id":"eba55887a0d79031","repo":"alibaba/spring-ai-alibaba","slug":"unsupported-search-type","errorCode":null,"errorMessage":"Unsupported search type: ","messagePattern":"Unsupported search type: ","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":261,"sourceCode":"\n\tprivate BulkResponse bulkRequest(BulkRequest bulkRequest) {\n\t\ttry {\n\t\t\treturn this.elasticsearchClient.bulk(bulkRequest);\n\t\t}\n\t\tcatch (IOException e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t}\n\t}\n\n\t@Override\n\tpublic List<Document> doSimilaritySearch(SearchRequest searchRequest) {\n\t\tAssert.notNull(searchRequest, \"The search request must not be null.\");\n\n\t\treturn switch (searchRequest.getSearchType()) {\n\t\t\tcase SEMANTIC -> searchBySemantic(searchRequest);\n\t\t\tcase FULL_TEXT -> searchByFullText(searchRequest);\n\t\t\tcase HYBRID -> searchByHybrid(searchRequest);\n\t\t\tdefault -> throw new IllegalArgumentException(\"Unsupported search type: \" + searchRequest.getSearchType());\n\t\t};\n\t}\n\n\tprivate String getElasticsearchQueryString(Filter.Expression filterExpression) {\n\t\treturn Objects.isNull(filterExpression) ? \"*\"\n\t\t\t\t: this.filterExpressionConverter.convertExpression(filterExpression);\n\n\t}\n\n\tprivate Document toDocument(Hit<Document> hit, SearchType searchType) {\n\t\tDocument document = hit.source();\n\t\tDocument.Builder documentBuilder = document.mutate();\n\t\tif (hit.score() != null) {\n\t\t\tdocumentBuilder.metadata(DocumentMetadata.DISTANCE.value(), 1 - normalizeSimilarityScore(hit.score()));\n\n\t\t\tif (searchType == SearchType.FULL_TEXT) {\n\t\t\t\tdocumentBuilder.score(1 - hit.score());\n\t\t\t}","sourceCodeStart":243,"sourceCodeEnd":279,"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#L243-L279","documentation":"doSimilaritySearch dispatches on SearchRequest.getSearchType() via a switch over SEMANTIC, FULL_TEXT, and HYBRID; any other value throws IllegalArgumentException(\"Unsupported search type: ...\"). Since Java switch over an enum covers all constants, this default arm mainly fires for null or unexpected/custom search types.","triggerScenarios":"Calling VectorStore.similaritySearch(SearchRequest) with a SearchRequest whose searchType is not one of the supported SEMANTIC/FULL_TEXT/HYBRID values — e.g. null searchType or a type introduced in a different version of the SearchRequest model.","commonSituations":"Building SearchRequest without explicitly setting searchType and getting an unexpected default; version skew between the SearchRequest class and this vector store implementation; copy-paste of a search type name from another vector store.","solutions":["Explicitly set SearchRequest.builder().searchType(SearchType.SEMANTIC) (or FULL_TEXT/HYBRID) when constructing the request.","Check that the SearchRequest class version matches the vector store module (version skew).","Ensure searchType is not null before calling similaritySearch.","Only use search types documented for this Elasticsearch vector store."],"exampleFix":"// before\nSearchRequest request = SearchRequest.builder().query(\"q\").topK(5).build();\n// after\nSearchRequest request = SearchRequest.builder().query(\"q\").topK(5)\n    .searchType(SearchType.SEMANTIC)\n    .build();","handlingStrategy":"validation","validationCode":"// Java\nSearchType t = searchRequest.getSearchType();\nif (t != SearchType.SEMANTIC && t != SearchType.FULL_TEXT && t != SearchType.HYBRID) {\n    throw new IllegalArgumentException(\"search type must be SEMANTIC, FULL_TEXT, or HYBRID: \" + t);\n}","typeGuard":"static boolean isSupported(SearchRequest req) {\n    return req != null && req.getSearchType() != null\n        && (req.getSearchType() == SearchType.SEMANTIC\n         || req.getSearchType() == SearchType.FULL_TEXT\n         || req.getSearchType() == SearchType.HYBRID);\n}","tryCatchPattern":"try { return vectorStore.similaritySearch(request); } catch (IllegalArgumentException e) {\n    if (String.valueOf(e.getMessage()).startsWith(\"Unsupported search type\")) { log.error(\"bad searchType: {}\", request.getSearchType()); }\n    throw e;\n}","preventionTips":["Always set searchType explicitly in SearchRequest builders.","Keep SearchRequest/VectorStore dependencies on the same version to avoid enum skew.","Reject unsupported search types at API boundary before hitting the store.","Add unit tests per search type you intend to use."],"tags":["elasticsearch","vector-store","search-type"],"backgroundTag":"unsupported-operation","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"}