# Should Query with Filter

**URL:** <https://discuss.elastic.co/t/should-query-with-filter/110560>\
**Category:** Elasticsearch\
**Created:** [December 6, 2017, 6:40pm UTC](https://discuss.elastic.co/t/should-query-with-filter/110560 "2017-12-06T18:40:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![full\_vlad](https://avatars.discourse-cdn.com/v4/letter/f/eb8c5e/32.png) [@full\_vlad](https://discuss.elastic.co/u/full_vlad)\
**Post date:** [December 6, 2017, 6:40pm UTC](https://discuss.elastic.co/t/should-query-with-filter/110560/1 "2017-12-06T18:40:21Z")

</div>

Hello everybody!

Given that types will be dropped in future releases I wanted to move them in a special field for each document (as stated [here](https://www.elastic.co/guide/en/elasticsearch/reference/6.0/removal-of-types.html#_custom_type_field)).

Now for the search query I'll have something like this:

```
{
    "query": {
        "bool" : {
            "should" : [
                { "match_phrase": { "field1": { "query": "test", "_name": "field1" }}},
                { "match": { "field2": { "query": "test", "_name": "field2"}}},
                { "match_phrase": { "field3": { "query": "test", "_name": "field3"}}},
                { "match": { "field4": { "query": "test", "_name": "field4"}}},
                { "match": { "field5": { "query": "test", "_name": "field5"}}}
            ],
            "filter": {
              "match": {
                "type_field": "important_type_name"
              }
            }
        }
    }
}

```

The only addition from what I used to have here is the `filter` for the exact match on the custom field `type_field`, which has `keyword` as type in its mapping.

The problem now is that this search will include **all** documents that have "type\_field" = "important\_type\_name". As stated [here](https://www.elastic.co/guide/en/elasticsearch/reference/6.x/query-dsl-bool-query.html#query-dsl-bool-query) in the `should` section, the should will only act in influencing the score.

How can I make a query that uses the `should` bool query but that has a strict filter on it? i.e. I want to use the capabilities of should (with fuzziness, boosting and match or match\_phrase) on multiple fields but still be sure that it looks only through some already filtered documents, and all the final results will have `matched_queries` (that's why I used the named queries, to show that right now, some resulted documents don't have any matched queries but are still part of the final result).

Thanks very much in advance!

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [December 6, 2017, 9:23pm UTC](https://discuss.elastic.co/t/should-query-with-filter/110560/2 "2017-12-06T21:23:20Z")

</div>

I think that setting minimum\_should\_match: 1 in the should array would help here.

See [https://www.elastic.co/guide/en/elasticsearch/reference/6.0/query-dsl-bool-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/6.0/query-dsl-bool-query.html)

---

<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:** [January 3, 2018, 9:23pm UTC](https://discuss.elastic.co/t/should-query-with-filter/110560/3 "2018-01-03T21:23:34Z")

</div>

Closed on January 3, 2018, 9:23pm UTC

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