# Use \_score as tiebreaker only for function\_score query

**URL:** <https://discuss.elastic.co/t/use-score-as-tiebreaker-only-for-function-score-query/122847>\
**Category:** Elasticsearch\
**Created:** [March 7, 2018, 8:56am UTC](https://discuss.elastic.co/t/use-score-as-tiebreaker-only-for-function-score-query/122847 "2018-03-07T08:56:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![masterada](https://avatars.discourse-cdn.com/v4/letter/m/5daacb/32.png) [@masterada](https://discuss.elastic.co/u/masterada)\
**Post date:** [March 7, 2018, 8:56am UTC](https://discuss.elastic.co/t/use-score-as-tiebreaker-only-for-function-score-query/122847/1 "2018-03-07T08:56:15Z")

</div>

I would like to use the score from full text search as a tie-breaker only for my calculated score.  
In other words, I would like to sort by a custom script, and if the score returned by that script is equal for two documents, sort those two documents by full text relevancy.  
Currently i'm noramlizing \_score between 0 and 1 and using this query:

```
{
    "_source": false,
    "from": 0,
    "query": {
        "function_score": {
            "boost_mode": "replace",
            "functions": [{
                "script_score": {
                    "script": "if ('val1' == doc['my_field'].value) { return 2; } else if ('val2' == doc['my_field'].value) { return 1; } return 0;"
                },
                "weight": 10
            }, {
                "script_score": {
                    "script": " return 1 - (1 / (_score + 1)) ; "
                }
            }],
            "query": {
                "bool": {
                    "must": {
                        "match": {
                            "_all": {
                                "fuzziness": "AUTO",
                                "prefix_length": 2,
                                "query": "eum ducimus"
                            }
                        }
                    }
                }
            },
            "score_mode": "sum"
        }
    },
    "size": 100
}

```

Is there a better way to achieve this?

---

<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:** [April 4, 2018, 8:56am UTC](https://discuss.elastic.co/t/use-score-as-tiebreaker-only-for-function-score-query/122847/2 "2018-04-04T08:56:23Z")

</div>

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