# Query with multiple Should nested

**URL:** <https://discuss.elastic.co/t/query-with-multiple-should-nested/304324>\
**Category:** Elasticsearch\
**Created:** [May 10, 2022, 8:41am UTC](https://discuss.elastic.co/t/query-with-multiple-should-nested/304324 "2022-05-10T08:41:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Miguel\_BA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/miguel_ba/32/46926_2.png) [@Miguel\_BA](https://discuss.elastic.co/u/Miguel_BA)\
**Post date:** [May 10, 2022, 8:41am UTC](https://discuss.elastic.co/t/query-with-multiple-should-nested/304324/1 "2022-05-10T08:41:05Z")

</div>

Hello, I am trying to get a query where I can make a nested should without using nested fields.  
Example:

```auto

GET index1/_search
{ 
  "query": {
    "bool": {
      "should": [
        {"term": {"name": "mike"}},
        {"term": {"surname": "robison"}},
        {"bool": {
          "should": [
            {"term": {"id": 1}},
            {"term": {"country": "Italy"}}
            ]
          }
        }
      ]
    }
  }
}

```

With this query what I want is to search for documents with name mike or robison, from its results only return those with "id": 1 or "Italy".  
It is giving me all the results as if it were, "mike" or "robison" or "id": 1 or "Italy".  
The only solution I can think of is to separate the queries to remove a level of should.

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [May 10, 2022, 12:30pm UTC](https://discuss.elastic.co/t/query-with-multiple-should-nested/304324/2 "2022-05-10T12:30:40Z")

</div>

Hi!

Maybe this works:

```auto
{
  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "should": [
              {
                "term": {
                  "name": {
                    "value": "mike"
                  }
                }
              },
              {
                "term": {
                  "surname": {
                    "value": "robison"
                  }
                }
              }
            ]
          }
        },
        {
          "bool": {
            "should": [
              {
                "term": {
                  "id": 1
                }
              },
              {
                "term": {
                  "country": "Italy"
                }
              }
            ]
          }
        }
      ]
    }
  }
}

```

---

<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:** [June 7, 2022, 12:31pm UTC](https://discuss.elastic.co/t/query-with-multiple-should-nested/304324/3 "2022-06-07T12:31:16Z")

</div>

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