Reputation: 15
I am using Query String to query elastic search and below is my sample query.
{
"query_string" : {
"query" : "Sharmila"
}
}
I've field called FLAG in the documents. I want to boost the results if the FLAG== Y. As custom_score is deprecated, I want to use function_score
{
"query": {
"function_score": {
"query": {
"query_string": {
"query": "Sharmila"
},
"functions": [{
"script_score": {
"script": "_score * (doc['FLAG'].value == 'Y' ? 1.2 : 1)"
}
}],
}
}
}
}
I am getting exception saying No query registered for [script_score]]
I am using elasticsearch 1.2.2
Any thoughts where I am doing wrong?
Upvotes: 0
Views: 676
Reputation: 217254
You're almost there, you just need to move the functions
property just below the function_score
one and not bury it inside your query
:
{
"query": {
"function_score": {
"functions": [{
"script_score": {
"script": "_score * (doc['FLAG'].value == 'Y' ? 1.2 : 1)"
}
}],
"query": {
"query_string": {
"query": "Sharmila"
}
}
}
}
}
Upvotes: 1