Hello, I have a question.
Our search platform generates our query dynamically depending on the query.
We use function_score scoring to modify our search ordering.
"boost_mode" is "replace" in order to take only our "functions" scoring.
And our "functions" have some weight in order to get our desired scoring instead of tfidf match scores.
Sample query is like below. (query is modified from original so please ignore some minor details)
{
"_source": false,
"query": {
"function_score": {
"boost_mode": "replace",
"score_mode": "sum",
"functions": [
{
"filter": {
"term": {
"region_id": 5
}
},
"weight": 10
},
{
"filter": {
"term": {
"title": "some query"
}
},
"weight": 10
}
],
"query": {
"bool": {
"must": [
{
"simple_query_string": {
"fields": [
"title"
],
"query": "some query",
"default_operator": "AND"
}
}
],
"must_not": [
{
"simple_query_string": {
"fields": [
"title"
],
"query": "some negative query",
"default_operator": "AND"
}
}
]
}
}
}
}
}
Then the issue is when "functions" are empty. In this case even though I set "boost_mode" to "replace" which should ignore "query" scores, the function_score will take "query" scores.
But I want it to have 0 score if "functions" are empty, as "replace" should ignore "query" score.
{
"_source": false,
"query": {
"function_score": {
"boost_mode": "replace",
"score_mode": "sum",
"functions": [ ],
"query": {
"bool": {
"must": [
{
"simple_query_string": {
"fields": [
"title"
],
"query": "some query",
"default_operator": "AND"
}
}
],
"must_not": [
{
"simple_query_string": {
"fields": [
"title"
],
"query": "some negative query",
"default_operator": "AND"
}
}
]
}
}
}
}
}
So I have 2 questions.
-
Is it desired feature that when "functions" are empty and "boost_mode" is "replace" then the "query" score is used?
(even though "replace" should ignore "query" score) -
The solution to this issue can be to add some dummy scoring function in the "functions".
What kind of dummy scoring function would you recommend?
I am thinking about below "functions" query.
{
"filter": {
"match_all": {
}
},
"weight": 0
}