# Function\_score, multi\_match, script\_score, and filter in Elasticsearch

**URL:** <https://discuss.elastic.co/t/function-score-multi-match-script-score-and-filter-in-elasticsearch/120720>\
**Category:** Elasticsearch\
**Created:** [February 20, 2018, 8:20pm UTC](https://discuss.elastic.co/t/function-score-multi-match-script-score-and-filter-in-elasticsearch/120720 "2018-02-20T20:20:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hacker\_21](https://avatars.discourse-cdn.com/v4/letter/h/a6a055/32.png) [@hacker\_21](https://discuss.elastic.co/u/hacker_21)\
**Post date:** [February 20, 2018, 8:20pm UTC](https://discuss.elastic.co/t/function-score-multi-match-script-score-and-filter-in-elasticsearch/120720/1 "2018-02-20T20:20:54Z")

</div>

I'm having trouble adding a filter to my existing multimatch query which is embedded inside of a function\_score.

Ideally, I'd like to filter by `"term" : { "lang" : "en" }`, only get back documents which are in the english language.

I've tried moving around the order, tried wrapping my query in bool, but just can't get the filter to work with the other functions I'm using.

My query code:

```
GET /my_index/_search/
{
  "query": {
    "function_score": {
      "query": {
        "bool": {
          "filter": {
            "term": {
              "lang": "en"
            }
          },
          "multi_match": {
            "query": "Sample Query here",
            "type": "most_fields",
            "fields": [
              "body",
              "title",
              "permalink",
              "name"
            ]
          }
        }
      },
      "script_score": {
        "script": {
          "source": "_score + 10"
        }
      }
    }
  }
}

```

Error code:  
{  
"error": {  
"root\_cause": [  
{  
"type": "parsing\_exception",  
"reason": "[bool] query does not support [multi\_match]",  
"line": 11,  
"col": 19  
}  
],  
"type": "parsing\_exception",  
"reason": "[bool] query does not support [multi\_match]",  
"line": 11,  
"col": 19  
},  
"status": 400  
}

I'm using the latest version of Elasticsearch (I believe 6.2)

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [February 20, 2018, 8:42pm UTC](https://discuss.elastic.co/t/function-score-multi-match-script-score-and-filter-in-elasticsearch/120720/2 "2018-02-20T20:42:04Z")

</div>

Place your multi\_match query inside a must or should clause. Since you only  
have one query, I would place it inside the must clause.

"bool": {  
"filter": {  
"term": {  
"lang": "en"  
}  
},  
"must": {  
"multi\_match": {  
"query": "Sample Query here",  
...  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![hacker\_21](https://avatars.discourse-cdn.com/v4/letter/h/a6a055/32.png) [@hacker\_21](https://discuss.elastic.co/u/hacker_21)\
**Post date:** [February 20, 2018, 8:56pm UTC](https://discuss.elastic.co/t/function-score-multi-match-script-score-and-filter-in-elasticsearch/120720/3 "2018-02-20T20:56:26Z")

</div>

> [@Ivan](#):
>
> "filter": {
> 
> "term": {
> 
> "lang": "en"
> 
> }
> 
> },

Thanks Ivan!

---

<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 20, 2018, 8:56pm UTC](https://discuss.elastic.co/t/function-score-multi-match-script-score-and-filter-in-elasticsearch/120720/4 "2018-03-20T20:56:35Z")

</div>

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