How to use OR and AND in elasticsearch

Viewed 15

I have:

[
{
    "example_1": false,
    "example_2": "example_string_1",
    "example_3": "example_string_2",
    "example_4": "example_string_3"
},

I need to write a python script, but testing it in POSTMAN right now. I need to print only blocks:

with ('false' example_1) AND (example_2 with one of two specific strings) AND (example_3 with one of the 6 specific strings)

I was testing some code snippets and

{
  "default_field" : "example_1",
  "query": "example_string_1"

was working nice, but I don't know how to add multiple conditions. I'm using this in POSTMAN's "BODY", something like:

{"query": (example_1:example_string_1 AND example_2:example_string_2) OR ...}

would be really nice (query DSL).

1 Answers

I think this query can be a start. If you want to use OR use should, AND use must

{
  "query": {
    "bool": {
      "filter": [
        {
          "term": {
            "example_1": false
          }
        },
        {
          "terms": {
            "example_2": [
              "VALUE1",
              "VALUE2"
            ]
          }
        },
        {
          "terms": {
            "example_3": [
              "VALUE1",
              "VALUE2"
            ]
          }
        }
      ]
    }
  }
}
Related