# Multiple Must queries not working inside a should query as expected

**URL:** <https://discuss.elastic.co/t/multiple-must-queries-not-working-inside-a-should-query-as-expected/298024>\
**Category:** Elasticsearch\
**Tags:** eql-elastic-query-language\
**Created:** [February 23, 2022, 11:58am UTC](https://discuss.elastic.co/t/multiple-must-queries-not-working-inside-a-should-query-as-expected/298024 "2022-02-23T11:58:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Venkat\_Pavan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/venkat_pavan/32/102210_2.png) [@Venkat\_Pavan](https://discuss.elastic.co/u/Venkat_Pavan)\
**Post date:** [February 23, 2022, 11:58am UTC](https://discuss.elastic.co/t/multiple-must-queries-not-working-inside-a-should-query-as-expected/298024/1 "2022-02-23T11:58:52Z")

</div>

I am trying to write a query of the form A or B or C or D where condition A is of the form A11 and A12, similarly B = B11 and B12 and so on. I am using elastic version 6.8 and executing the queries in Kibana. I have added "\_name" to track which documents matched what conditions.

```auto
{
  "size": "1000",
  "query": {
    "bool": {
      "should": [
        {
          "bool": {
            "must": [
              {
                "match": {
                  "taxRegistrationNumber_processed.lowercase_keyword": {
                    "query": "111222333",
                    "operator": "OR",
                    "fuzziness": "2",
                    "prefix_length": 0,
                    "max_expansions": 50,
                    "fuzzy_transpositions": true,
                    "lenient": false,
                    "zero_terms_query": "NONE",
                    "boost": 1,
                    "_name": "A11"
                  }
                }
              },
              {
                "match": {
                  "doc_mapping_type": {
                    "query": "merchant",
                    "operator": "OR",
                    "prefix_length": 0,
                    "max_expansions": 50,
                    "fuzzy_transpositions": true,
                    "lenient": false,
                    "zero_terms_query": "NONE",
                    "boost": 1,
                    "_name": "A12"
                  }
                }
              }
            ],
            "adjust_pure_negative": true,
            "boost": 1
          }
        },
        {
          "bool": {
            "must": [
              {
                "match": {
                  "taxRegistrationNumber_processed": {
                    "query": "111222333",
                    "operator": "OR",
                    "fuzziness": "2",
                    "prefix_length": 0,
                    "max_expansions": 50,
                    "fuzzy_transpositions": true,
                    "lenient": false,
                    "zero_terms_query": "NONE",
                    "boost": 1,
                    "_name": "B11"
                  }
                }
              },
              {
                "match": {
                  "doc_mapping_type": {
                    "query": "merchant",
                    "operator": "OR",
                    "prefix_length": 0,
                    "max_expansions": 50,
                    "fuzzy_transpositions": true,
                    "lenient": false,
                    "zero_terms_query": "NONE",
                    "boost": 1,
                    "_name": "B12"
                  }
                }
              }
            ],
            "adjust_pure_negative": true,
            "boost": 1
          }
        },
        {
          "bool": {
            "must": [
              {
                "match": {
                  "owner_fullName_processed": {
                    "query": "test user",
                    "operator": "OR",
                    "fuzziness": "AUTO",
                    "prefix_length": 0,
                    "max_expansions": 50,
                    "fuzzy_transpositions": true,
                    "lenient": false,
                    "zero_terms_query": "NONE",
                    "boost": 1,
                    "_name": "C11"
                  }
                }
              },
              {
                "match": {
                  "doc_mapping_type": {
                    "query": "owners",
                    "operator": "OR",
                    "prefix_length": 0,
                    "max_expansions": 50,
                    "fuzzy_transpositions": true,
                    "lenient": false,
                    "zero_terms_query": "NONE",
                    "boost": 1,
                    "_name": "C12"
                  }
                }
              }
            ],
            "adjust_pure_negative": true,
            "boost": 1
          }
        },
        {
          "bool": {
            "must": [
              {
                "match": {
                  "owner_fullName_processed.lowercase_keyword": {
                    "query": "test user",
                    "operator": "OR",
                    "fuzziness": "2",
                    "prefix_length": 0,
                    "max_expansions": 50,
                    "fuzzy_transpositions": true,
                    "lenient": false,
                    "zero_terms_query": "NONE",
                    "boost": 1,
                    "_name": "D11"
                  }
                }
              },
              {
                "match": {
                  "doc_mapping_type": {
                    "query": "owners",
                    "operator": "OR",
                    "prefix_length": 0,
                    "max_expansions": 50,
                    "fuzzy_transpositions": true,
                    "lenient": false,
                    "zero_terms_query": "NONE",
                    "boost": 1,
                    "_name": "D12"
                  }
                }
              }
            ],
            "adjust_pure_negative": true,
            "boost": 1
          }
        }
      ]
    }
  }
}

``
I am getting documents with the following 

```

"matched\_queries": [

```
      "A11",

      "C12",

      "B11",

      "C11",

      "D11",

      "D12"

    ]

```

```auto
My requirement is if a document satisfied condition A11 it must also satisfy A12. 
Same goes for others.
Thanks for the help :slight_smile: .
```

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [February 23, 2022, 4:51pm UTC](https://discuss.elastic.co/t/multiple-must-queries-not-working-inside-a-should-query-as-expected/298024/2 "2022-02-23T16:51:41Z")

</div>

It looks like your document matched your logic correctly - C had both of the required 11s and 12s. The other reported half-matches for A and B are just added info you requested. If you are only interested in “x11 AND x12” match reporting shift the \_name param up one level to the Bool that contains the 11 and 12 clauses and rename it to something appropriate eg b11&b12

---

<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 23, 2022, 4:52pm UTC](https://discuss.elastic.co/t/multiple-must-queries-not-working-inside-a-should-query-as-expected/298024/3 "2022-03-23T16:52:30Z")

</div>

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