结合必须和应该

Pie*_*nes 1 elasticsearch elasticsearch-5

我在使用Elasticsearch查询时遇到了一些麻烦。(我使用elasticsearch 5)。我想结合必须布尔查询和应该为了创建一个符合此条件的查询:

Get users which match (city = x) AND (school = y) AND (age = 12) AND (team = a OR b)
Run Code Online (Sandbox Code Playgroud)

我尝试了许多查询,但仍然有格式错误的查询异常。

{
  "query": {
    "bool": {
      "must" : [
        {
          "match": {
            "city": "x"
          }
        },
        {
          "match" : {
            "school" : "y"
        }
        },
        {
          "match" : {
            "age" : 12
        },
          "bool": {
            "should": [
              {"term": {"team": "A"}},
              {"term": {"team": "B"}}
            ]
          }
        }
      ]
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我希望有人可以帮助我:D

谢谢你的帮助

And*_*fan 5

这对我有用:

{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "city": "x"
          }
        },
        {
          "match": {
            "school": "y"
          }
        },
        {
          "match": {
            "age": 12
          }
        },
        {
          "bool": {
            "should": [
              {
                "term": {
                  "team": "A"
                }
              },
              {
                "term": {
                  "team": "B"
                }
              }
            ]
          }
        }
      ]
    }
  }
}
Run Code Online (Sandbox Code Playgroud)