我正在尝试在
knn
查询下的搜索 API 中使用 bool
。但是得到和错误。我正在使用弹性搜索 8.6.2
这是我的查询
GET document-with-embeddings/_search
{
"query":
{
"bool": {
"must": [
{
"knn": {
"text_embedding.predicted_value": {
"vector": [
-0.06544870883226395,
-0.21647875010967255,
...................
],
"k": 20
}
}
}
],
"filter": [],
"should": [],
"must_not": []
}
},
"_source": [
"name", "description"
]
}
我的嵌入索引是
properties": {
"text_embedding.predicted_value": {
"type": "dense_vector",
"dims": 384,
"index": true,
"similarity": "cosine"
},
我收到了这个错误。
{
"error": {
"root_cause": [
{
"type": "x_content_parse_exception",
"reason": "[7:28] [bool] failed to parse field [must]"
}
],
"type": "x_content_parse_exception",
"reason": "[7:28] [bool] failed to parse field [must]",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "[knn] queries cannot be provided directly, use the [knn] body parameter instead"
}
},
"status": 400
}
这里补充一点,我会使用复杂查询。这就是我使用 bool 的原因。但是下面的一个简单查询对我有用,这不是我的目标。
GET document-with-embeddings/_search
{
"knn": {
"field": "text_embedding.predicted_value",
"query_vector": [...],
"k": 20,
"num_candidates": 1000
},
"_source": [
"custom"
]
}
任何帮助表示赞赏。