Skip to content

ES 混合检索 IN语句失败 search_phase_execution_exception #3826

Open
@yw5579358

Description

@yw5579358

[es/search] failed: [search_phase_execution_exception] all shards failed
失败描述:
ErrorResponse: {"error":{"phase":"dfs","failed_shards":[{"shard":0,"index":"my-index3","node":"Ca88lI66TmmhcJ4-jI_QPA","reason":{"type":"query_shard_exception","reason":"Failed to parse query [(metadata.id:[1752564273802, 1752564273799]) AND metadata.index_name:my-index3]","index_uuid":"bAjSAYbURCqt1XZ08ujcDw","index":"my-index3","caused_by":{"type":"parse_exception","reason":"Cannot parse '(metadata.id:[1752564273802, 1752564273799]) AND metadata.index_name:my-index3': Encountered " <RANGE_GOOP> "1752564273799 "" at line 1, column 29.\nWas expecting:\n "TO" ...\n ","caused_by":{"type":"parse_exception","reason":"Encountered " <RANGE_GOOP> "1752564273799 "" at line 1, column 29.\nWas expecting:\n "TO" ...\n "}}}}],"grouped":true,"type":"search_phase_execution_exception","reason":"all shards failed","root_cause":[{"index_uuid":"bAjSAYbURCqt1XZ08ujcDw","index":"my-index3","type":"query_shard_exception","reason":"Failed to parse query [(metadata.id:[1752564273802, 1752564273799]) AND metadata.index_name:my-index3]"}]},"status":400}

FilterExpressionBuilder 中使用In语句,向量库使用ES,在调用过程中IN语句被转换为了范围查询
代码如下:
调用:
SearchRequest searchRequest = buildSearchRequest(usedDocIds,message, vectorIndexName);
List relevantDocs = vectorStore.similaritySearch(searchRequest);
方法:
private SearchRequest buildSearchRequest(List useDocumentIds,String message, String vectorIndexName) {
if (vectorIndexName == null || vectorIndexName.isEmpty()) {
return null;
}
FilterExpressionBuilder b = new FilterExpressionBuilder();
if (!CollectionUtils.isEmpty(useDocumentIds)) {
Filter.Expression filter = b.and(
b.in("id", useDocumentIds),
b.eq("index_name", vectorIndexName)
).build();
return SearchRequest.builder()
.query(message)
.similarityThreshold(0)
.filterExpression(filter)
.topK(10)
.build();
}
return SearchRequest.builder()
.query(message)
.similarityThreshold(similarityThreshold)
.topK(10)
.filterExpression(b.eq("index_name", vectorIndexName).build())
.build();
}
ES索引如下:
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
},
"mappings": {
"properties": {
"id": { "type": "keyword" },
"title": { "type": "text" },
"publish_time": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||strict_date_optional_time||epoch_millis"
},
"knowledge_base_id": { "type": "keyword" },
"index_name": { "type": "keyword" },
"tag_ids": { "type": "long" },
"file_name": { "type": "keyword" },
"file_path": { "type": "keyword" },
"embedding": {
"type": "dense_vector",
"dims": %d,
"index": true,
"similarity": "cosine"
}
}
}
}
spring ai版本:

org.springframework.ai
spring-ai-bom
1.0.0
pom
import

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions