# Range + Boolean Queries on Nested Objects

**URL:** https://discuss.elastic.co/t/range-boolean-queries-on-nested-objects/183792
**Category:** Elasticsearch
**Created:** [May 31, 2019, 9:26pm UTC](https://discuss.elastic.co/t/range-boolean-queries-on-nested-objects/183792 "2019-05-31T21:26:11Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jerryt](https://avatars.discourse-cdn.com/v4/letter/j/4da419/32.png) [@jerryt](https://discuss.elastic.co/u/jerryt)
#### Post date: [May 31, 2019, 9:26pm UTC](https://discuss.elastic.co/t/range-boolean-queries-on-nested-objects/183792/1 "2019-05-31T21:26:11Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![wangqinghuan](https://avatars.discourse-cdn.com/v4/letter/w/d26b3c/32.png) [@wangqinghuan](https://discuss.elastic.co/u/wangqinghuan)
#### Post date: [June 1, 2019, 2:52pm UTC](https://discuss.elastic.co/t/range-boolean-queries-on-nested-objects/183792/2 "2019-06-01T14:52:38Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [June 29, 2019, 2:52pm UTC](https://discuss.elastic.co/t/range-boolean-queries-on-nested-objects/183792/3 "2019-06-29T14:52:43Z")

</div>

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