Skip to content

Instantly share code, notes, and snippets.

@omarsar
Created September 16, 2019 14:52
Show Gist options
  • Save omarsar/33f2b6ceafd6b6c336570012ca8eaad2 to your computer and use it in GitHub Desktop.
Save omarsar/33f2b6ceafd6b6c336570012ca8eaad2 to your computer and use it in GitHub Desktop.
Bool Query with OR and AND
GET blogs_fixed/_search
{
    "query": {
        "query_string" : {
            "query" : "(content:elasticsearch AND content:engineering) OR (title:elasticsearch AND title:engineering)"
        }
    }
}
GET blogs_fixed/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "bool": {
            "must": [
              {
                "match": {
                  "content": "elasticsearch"
                }
              },
              {
                "match": {
                  "content": "engineering"
                }
              }
            ]
          }
        },
        {
          "bool": {
            "must": [
              {
                "match": {
                  "title": "elasticsearch"
                }
              },
              {
                "match": {
                  "title": "engineering"
                }
              }
            ] 
          }
        }
      ],
      "minimum_should_match": 1
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment