Query with multiple Should nested

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


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.

Hi!

Maybe this works:

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

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