# Scoring for words and fetch docs that get minimum score

**URL:** <https://discuss.elastic.co/t/scoring-for-words-and-fetch-docs-that-get-minimum-score/24224>\
**Category:** Elasticsearch\
**Created:** [June 23, 2015, 10:37pm UTC](https://discuss.elastic.co/t/scoring-for-words-and-fetch-docs-that-get-minimum-score/24224 "2015-06-23T22:37:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dekel](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@Dekel](https://discuss.elastic.co/u/Dekel)\
**Post date:** [June 23, 2015, 10:37pm UTC](https://discuss.elastic.co/t/scoring-for-words-and-fetch-docs-that-get-minimum-score/24224/1 "2015-06-23T22:37:59Z")

</div>

I'm looking for a way to give words a score (different score for each word) and find docs that match a minimum score (based on the scores and the words).

The idea is that I might have words with high score (wordA - score=5) and I want all docs that has wordA, but I also have words with lower score (wordB, wordC, wordD - score=2). If i want docs that match minimum of score=4 I would like to get the docs that has wordA or any combination of 2 of (wordB, wordC, wordD).  
Same goes with minimum score of 6 - the result should be docs contains wordA and one of (wordB, wordC, wordD), or docs contains all 3 of (wordB, wordC, wordD).

I was trying to boost words combined with minimum\_should\_match, but it doesn't really do the trick. Any ideas of how I can do that?

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [June 24, 2015, 6:38pm UTC](https://discuss.elastic.co/t/scoring-for-words-and-fetch-docs-that-get-minimum-score/24224/2 "2015-06-24T18:38:56Z")

</div>

If you need the explicit scoring (e.g you don't want TF-IDF derived scores), you can use the `function_score` to set your own custom scoring based on lists of terms and their weightings. For example:

```json

POST test/test
{
  "title": "wordA wordB wordC"
}

POST test/test
{
  "title": "wordD"
}

POST test/test
{
  "title": "wordB wordC"
}

POST test/test
{
  "title": "wordC"
} 

GET /test/_search
{
  "query": {
    "function_score": {
      "functions": [
        {
          "filter": {
            "terms": {
              "title": ["worda"]
            }
          },
          "weight": 5
        },
        {
          "filter": {
            "terms": {
              "title": ["wordd"]
            }
          },
          "weight": 3
        },
        {
          "filter": {
            "terms": {
              "title": ["wordb"]
            }
          },
          "weight": 1
        },
        {
          "filter": {
            "terms": {
              "title": ["wordc"]
            }
          },
          "weight": 2
        }
      ],
      "score_mode": "sum"
    }
  },
  "min_score": 3
}

```

Each `filter` function contains a `terms` which includes the list of tokens for a given weight. The function score is then configured to sum up the weights. Then we configure the query to have a minimum score of 3, which excludes documents that haven't accumulated enough "weight".

You could also use the [Terms Lookup functionality](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-filter.html#_terms_lookup_mechanism) to index those term lists, instead of specifying them in the query itself

---

<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:** [July 6, 2017, 12:05am UTC](https://discuss.elastic.co/t/scoring-for-words-and-fetch-docs-that-get-minimum-score/24224/3 "2017-07-06T00:05:33Z")

</div>


