# How to use specific filter score in score function script

**URL:** <https://discuss.elastic.co/t/how-to-use-specific-filter-score-in-score-function-script/170008>\
**Category:** Elasticsearch\
**Created:** [February 26, 2019, 12:47pm UTC](https://discuss.elastic.co/t/how-to-use-specific-filter-score-in-score-function-script/170008 "2019-02-26T12:47:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fabiomrch](https://avatars.discourse-cdn.com/v4/letter/f/278dde/32.png) [@fabiomrch](https://discuss.elastic.co/u/fabiomrch)\
**Post date:** [February 26, 2019, 12:47pm UTC](https://discuss.elastic.co/t/how-to-use-specific-filter-score-in-score-function-script/170008/1 "2019-02-26T12:47:10Z")

</div>

Hi everyone,

I want to execute the following query in order to get a score that combines many conditions. Each result must respect a precondition (query) and each filter in functions must have a role in calculating output score. I realised that \_score in script\_score always returns main query score value while I need specific filter condition score (e.g. description match).

```
{"query":
  {"function_score":
    {
    "query":
      {"match":{"supplierName":{"query":"Company","operator":"OR","prefix_length":0,"max_expansions":50,"fuzzy_transpositions":true,"lenient":false,"zero_terms_query":"NONE","auto_generate_synonyms_phrase_query":true,"boost":1}}},
    "functions":[
          {"filter":{"terms":{"num":["43412453"],"boost":1}},"weight":44.4},
          {"filter":{"match":{"supplierName":{"query":"Company","operator":"OR","prefix_length":0,"max_expansions":50,"fuzzy_transpositions":true,"lenient":false,"zero_terms_query":"NONE","auto_generate_synonyms_phrase_query":true,"boost":1}}},"script_score":{"script":{"source":"Math.min(_score, 1) * 33.333336","lang":"painless"}}},
          {"filter":{"match":{"description":{"query":"Product X","operator":"OR","prefix_length":0,"max_expansions":50,"fuzzy_transpositions":true,"lenient":false,"zero_terms_query":"NONE","auto_generate_synonyms_phrase_query":true,"boost":1}}},"script_score":{"script":{"source":"Math.min(_score / 3.08, 1) * 22.2","lang":"painless"}}}
        ],
        "score_mode":"sum",
        "boost_mode":"replace",
        "min_score":40.0,
        "boost":1
      }
  }      
}
```

---

<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:** [March 26, 2019, 12:47pm UTC](https://discuss.elastic.co/t/how-to-use-specific-filter-score-in-score-function-script/170008/2 "2019-03-26T12:47:12Z")

</div>

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