Reputation: 11
I want to implement a knn search in elastic on a particular field (on an ipython notebook), and my data also contains ratings (from 1 to 5), which I also want to be taken into consideration, and hence i am implementing a functional boost as follows:
query = {
"field" : "DescriptionVector",
"query_vector": vector_of_input_keyword,
"k": 2,
"num_candidates": 500,
"boosts": [
{
"type": "functional",
"operation": "multiply",
"factor": 0.1,
"function": {
"field": "Ratings"
}
}
]
}
res = es.search(index="all_products", knn=query, _source=["ProductName", "Description"])
but, the above code gives an error: BadRequestError(400, 'x_content_parse_exception', '[1:16260] [knn] unknown field [boosts] did you mean [boost]?')
Now I know there is an error in syntax but cannot figure out what it is, could someone help me out, thanks!
Upvotes: 1
Views: 444
Reputation: 46
You can combine knn with regular queries for hybrid search, but you would separate the two. See the docs here; and this example:
"query": {
"match": {
"title": {
"query": "mountain lake",
"boost": 0.9
}
}
},
"knn": {
"field": "image-vector",
"query_vector": [54, 10, -2],
"k": 5,
"num_candidates": 50,
"boost": 0.1
},
"size": 10
Hope this helps!
Upvotes: 1