ES实战-组合查询或符合查询-bool

#组合查询case 含有must,should,must_not
GET /get-together/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
              "attendees": "David"
          }
        }
      ],
      "should": [
        {
          "term": {
              "attendees": "clint"
          }
        },
        {
          "term": {
              "attendees": "Andy"
          }
        }
      ],
      "must_not": [
        {
          "range": {
            "date": {
              "lt": "2013-06-30T00:00"
            }
          }
        }
      ],
      "minimum_should_match": 1
    }
  }
}
#换一种写法,
GET /get-together/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
              "attendees": "David"
          }
        },
        {
          "range": {
            "date": {
              "gte": "2013-06-30T00:00"
              }
          }
        },
        {
          "terms": {
            "attendees": [
              "clint",
              "Andy"
            ]
          }
        }
      ]
    }
  }
}

你可能感兴趣的:(elasticsearch)