0

Here is an example record that I have stored in ES:

  "taskCurateStatus": true,
  "taskMigrateStatus": true,
  "verifiedFields": 7,
  "taskId": "abcdef123",
  "operatorEmail": "[email protected]"

Example Query I'm making via /_search:
{
  "sort": [
    {
      "@timestamp": {
        "order": "desc"
      }
    }
  ],
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "msg.operator_email": "[email protected]"
          }
        }
        {
          "range": {
            "@timestamp": {
              "gte": "2017-03-05",
              "lte": "2017-03-12"
            }
          }
        }
      ]
    }
  },
  "from": 0,
  "size": 50
}

Basically I want to also filter by documents that have EITHER taskCurateStatus or taskMigrateStatus be true. Some messages have only one of them defined. I was thinking of using a should query but not sure how that would work with the match query. Any help would be appreciated. Thanks

1 Answer 1

2

you can add another boolean filter inside your must filter. This boolean filter can implemenet the should clause where you can compare the boolean flags with a should filter combining both the boolean check filters

{
    "sort": [{
        "@timestamp": {
            "order": "desc"
        }
    }],
    "query": {
        "bool": {
            "must": [{
                "match": {
                    "msg.operator_email": "[email protected]"
                }
            }, {
                "range": {
                    "@timestamp": {
                        "gte": "2017-03-05",
                        "lte": "2017-03-12"
                    }
                }
            }, {
                "bool": {
                    "should": [{
                        "term": {
                            "taskCurateStatus": {
                                "value": true
                            }
                        }
                    }, {
                        "term": {
                            "taskMigrateStatus": {
                                "value": true
                            }
                        }
                    }]
                }
            }]
        }
    },
    "from": 0,
    "size": 50
}

Take a look at the above query and see if the helps Thanks

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.