You appear to have an extra query
in your search (giving a total of three), which is giving you an unwanted top-level. You need to remove the top-level query
and replace it with function_score
as the top level key.
res = es.search(index="article-index", fields="url", body={"function_score": {
"query": {
{ "query_string": {"query": keywordstr} }
},
"functions": {
"DECAY_FUNCTION": {
"recencyboost": {
"origin": "0",
"scale": "20"
}
}
},
"score_mode": "multiply"
})
Note: score_mode
defaults to "multiply"
, as does the unused boost_mode
, so it should be unnecessary to supply it.