Range + Boolean Queries on Nested Objects

Hi, I am new to ES. Have looked around for an answer, but was unable to find one...

Say, I have a data index like this

listing (parent)

  • availabilities (nested objects)
    • boolean
    • date

For a given date range, I'd like to return a listing if and only if all the boolean field is set to true.
My query looks like this

GET /listings/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "city": "Montreal"
          }
        },
        {
          "nested": {
            "path": "availabilities",
            "query": {
              "bool": {
                "must": [
                  {
                    "match": {
                      "availabilities.available": {
                        "query": true
                      }
                    }
                  },
                  {
                    "range": {
                      "availabilities.date": {
                        "gte": "2019-05-30",
                        "lt": "2019-06-01",
                        "relation": "within"
                      }
                    }
                  }
                ]
              }
            }
          }
        }
      ]
    }
  }
}

However, when I run the above query, it will return a listing when one of the boolean field is true. How can I modify my query? Thx for the help!

Nested documents are indexed as seperate documents, so your nested query was executed againse every seperate documents rather than the list of nested documents.
You could scroll all parent documents about "Montreal" and their corresponding child documents, and iterate all child documents for every parent document to execute logic.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.