源代码:
List<String> documentIds = (List<String>) requestBody.getOrDefault("documentIds", new ArrayList<>());
Filter.Expression filterExpression = null;
filterExpression = b.in("id", documentIds).build();
经过debug调试后,发现elastic的报错信息是:
ErrorCause@163 "ErrorCause: {"phase":"dfs","failed_shards":[{"shard":0,"index":"my-index","node":"5gGemd0KQeafjhS6eo5CZw","reason":{"type":"query_shard_exception","reason":"Failed to parse query [(metadata.id:[15, 25])]","index_uuid":"70QktWW0T7OhYORdpL1Lsg","index":"my-index","caused_by":{"type":"parse_exception","reason":"Cannot parse '(metadata.id:[15, 25])': Encountered \"
Comment From: markpollack
Please try to translate to english in future.
"When you use Elasticsearch as a vector database, an error is reported when you use the in condition query"
There are tests for this here - https://github.com/spring-projects/spring-ai/blob/4f4da3076a650617d3bc7794ecc6ed89acff2cf4/vector-stores/spring-ai-elasticsearch-store/src/test/java/org/springframework/ai/vectorstore/elasticsearch/ElasticsearchVectorStoreIT.java#L198 perhaps that helps.
Please provide a fully working repo example and we can investigate further.
Comment From: HellerZhang
I suspect there is an issue with the string format in the expression. When I use .filterExpression("id in ['25','26']")
, there is no problem. However, I noticed that in the result generated by b.in("id", documentIds).build();
, the metadata.id:[15, 25]
does not have quotation marks. The data stored in my vector database is in string format. Could this be related to the problem?