# Elasticsearch combining Filter with Bool by a Must

**URL:** <https://discuss.elastic.co/t/elasticsearch-combining-filter-with-bool-by-a-must/327863>\
**Category:** Elasticsearch\
**Created:** [March 16, 2023, 2:46pm UTC](https://discuss.elastic.co/t/elasticsearch-combining-filter-with-bool-by-a-must/327863 "2023-03-16T14:46:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MonikaJ](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/monikaj/32/117707_2.png) [@MonikaJ](https://discuss.elastic.co/u/MonikaJ)\
**Post date:** [March 16, 2023, 2:46pm UTC](https://discuss.elastic.co/t/elasticsearch-combining-filter-with-bool-by-a-must/327863/1 "2023-03-16T14:46:08Z")

</div>

I am trying to combine a "filter" with a "bool"/"should" inside a "must". The following query is automatically generated by an application (hence the nesting). How must the query look like to have an AND condition between the wildcard condition and the filter statement?

```auto
   "query":{
      "bool":{
         "filter": {
            "bool": {
              "must": [],
              "must_not": [],
              "should": [],
              "filter": {
                "bool": {
                  "should": [
                    {
                      "wildcard": {
                        "attachment.content_type.keyword": "video/*"
                      }
                    }
                  ],
                  "must": [],
                  "must_not": [],
                  "filter": [
                    {
                      "terms": {
                        "status.keyword": [
                          "xxx"
                        ]
                      }
                    }
                  ]
                }
              }
            }
          }
      }
   }

```

---

<div class="post-metadata">

**Author:** ![Wave](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wave/32/117242_2.png) [@Wave](https://discuss.elastic.co/u/Wave)\
**Post date:** [March 24, 2023, 4:45pm UTC](https://discuss.elastic.co/t/elasticsearch-combining-filter-with-bool-by-a-must/327863/2 "2023-03-24T16:45:15Z")

</div>

Having a hard time understanding what you are trying to do. In a boolean you usually want your "must", "must\_not", or "should" to have something in them, and then a filter to help things along.

Without knowing more here's a possibility:

```auto
{
  "query": {
    "bool": {
      "filter": {
        "term": {
          "status.keyword": "xxx"
        }
      },
      "should": [
        {
          "wildcard": {
            "attachment.content_type.keyword": "video/*"
          }
        }
      ]
    }
  }
}

```

Will that return what you are looking for?

---

<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:** [April 21, 2023, 4:45pm UTC](https://discuss.elastic.co/t/elasticsearch-combining-filter-with-bool-by-a-must/327863/3 "2023-04-21T16:45:29Z")

</div>

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