# Function score - boost\_mode replace when functions are empty

**URL:** https://discuss.elastic.co/t/function-score-boost-mode-replace-when-functions-are-empty/130937
**Category:** Elasticsearch
**Created:** [May 8, 2018, 5:58am UTC](https://discuss.elastic.co/t/function-score-boost-mode-replace-when-functions-are-empty/130937 "2018-05-08T05:58:56Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![giga811](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/giga811/32/26499_2.png) [@giga811](https://discuss.elastic.co/u/giga811)
#### Post date: [May 8, 2018, 5:58am UTC](https://discuss.elastic.co/t/function-score-boost-mode-replace-when-functions-are-empty/130937/1 "2018-05-08T05:58:56Z")

</div>

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)

```auto
{
  "_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.

```auto
{
  "_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.

1. 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)

2. 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.

```auto
{
  "filter": {
    "match_all": {
    }
  },
  "weight": 0
}

```

---

<div class="post-metadata">

### Author: ![giga811](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/giga811/32/26499_2.png) [@giga811](https://discuss.elastic.co/u/giga811)
#### Post date: [May 11, 2018, 7:44am UTC](https://discuss.elastic.co/t/function-score-boost-mode-replace-when-functions-are-empty/130937/2 "2018-05-11T07:44:45Z")

</div>

@elastic please someone have any idea on the first question? 🙇‍♂️

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [June 8, 2018, 7:44am UTC](https://discuss.elastic.co/t/function-score-boost-mode-replace-when-functions-are-empty/130937/3 "2018-06-08T07:44:48Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
