# Avg function score query only for matching filter

**URL:** https://discuss.elastic.co/t/avg-function-score-query-only-for-matching-filter/1687
**Category:** Elasticsearch
**Created:** [June 2, 2015, 7:23am UTC](https://discuss.elastic.co/t/avg-function-score-query-only-for-matching-filter/1687 "2015-06-02T07:23:42Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![ruben](https://avatars.discourse-cdn.com/v4/letter/r/59ef9b/32.png) [@ruben](https://discuss.elastic.co/u/ruben)
#### Post date: [June 2, 2015, 7:23am UTC](https://discuss.elastic.co/t/avg-function-score-query-only-for-matching-filter/1687/1 "2015-06-02T07:23:42Z")

</div>

Hi all,

Is there a way when using multiple filters in function score query to have the score mode "avg" only compute the average on the matching filters ?

My mapping is ( extract )

```
        "popularity": {
        "type": "nested",
        "include_in_parent": true,
        "properties": {
            "value": {
                "type": "integer"
            },
            "countryCode":{
                "type": "string",
                "index": "not_analyzed"
            }
        }
    }

```

Documents contains X popularity objects with different country codes and a World Wide country code, i want to use the avg of local country and world wide as boost to the query score. The problem is that if one document is missing the local country the value for World Wide will be divided by 2.

Thanks  
Ruben Chadien

---

<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:10am UTC](https://discuss.elastic.co/t/avg-function-score-query-only-for-matching-filter/1687/2 "2017-07-06T00:10:19Z")

</div>


