我试图在curl中复制下面的elasticsearch-py突击队
curl -XGET "localhost:9200/my-exact-knn-index/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"script_score": {
"query" : {
"bool" : {
"filter" : {
"range" : {
"my-price" : {
"gte": 0
}
}
}
}
},
"script": {
"source": "\n double value = dotProduct(params.query_vector, 'my-product-vector');\n return sigmoid(1, Math.E, -value); \n ",
"params": {
"query_vector": [-0.5, 90.0, -10, 14.8, -156.0]
}
}
}
}
}但是我很难理解如何为index.search()调用提供“脚本”部分。我尝试在query参数和body参数(现在不推荐)中提供它,但是它给了我一个BadRequestError
query_body = {
"script_score": {
"script": {
"source": "\n double value = dotProduct(params.query_vector, '\''my-product-vector'\'');\n return sigmoid(1, Math.E, -value); \n ",
"params": {
"query_vector": [-0.5, 90.0, -10, 14.8, -156.0]
}
}
}
}
search_results = client.search(index="my-exact-knn-index", query=query_body)
>>> BadRequestError: BadRequestError(400, 'illegal_argument_exception', 'Required [query]')知道该怎么做吗?
发布于 2022-07-11 11:19:17
就快到了,您只需要一个query部分:
query_body = {
"script_score": {
"query": { <----- add this
....
},
"script": {
"source": "\n double value = dotProduct(params.query_vector, '\''my-product-vector'\'');\n return sigmoid(1, Math.E, -value); \n ",
"params": {
"query_vector": [-0.5, 90.0, -10, 14.8, -156.0]
}
}
}
}
}发布于 2022-07-11 11:43:49
我做了以下几件事,让它发挥作用:
query_body = {
"script_score": {
"query" : {
"bool" : {
"filter" : {
"range" : {
"my-price" : {
"gte": 0
}
}
}
}
},
"script": {
"source": "\n double value = dotProduct(params.query_vector, 'my-product-vector');\n return sigmoid(1, Math.E, -value); \n ",
"params": {
"query_vector": [-0.5, 90.0, -10, 14.8, -156.0]
}
}
}
}
search_results = client.search(index="my-exact-knn-index", query=query_body)所以query不得不紧跟在script_score之后。
https://stackoverflow.com/questions/72937655
复制相似问题