# Search nested collection of ranges

**URL:** <https://discuss.elastic.co/t/search-nested-collection-of-ranges/9681>\
**Category:** Elasticsearch\
**Created:** [November 12, 2012, 8:08pm UTC](https://discuss.elastic.co/t/search-nested-collection-of-ranges/9681 "2012-11-12T20:08:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JohnnyPeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johnnypeck/32/2624_2.png) [@JohnnyPeck](https://discuss.elastic.co/u/JohnnyPeck)\
**Post date:** [November 12, 2012, 8:08pm UTC](https://discuss.elastic.co/t/search-nested-collection-of-ranges/9681/1 "2012-11-12T20:08:36Z")

</div>

I really need some guidance with a problem that's been vexing me for days  
now. I spoke with Kimchy on IRC and he suggested I post here. I have an  
index with rental properties. Each property has a nested collection of  
leases with a start and end date. I want the user to query with a start and  
end date that will return properties that DO NOT have a lease that overlaps  
with the submitted start and end. The user can also provide search terms,  
number of bedrooms, etc. Doing that search was not a problem. But filtering  
on the start and end dates is proving problematic.

An example property looks like:

{

```
_index: website
_type: property
_id: 9
_version: 1
_score: 1
_source: {
    id: 9
    ratePerDay: 115.00
    listingTitle: 851 North Glebe Road #2009
    locationNeighborhood.name: Arlington
    leases: [
        {
            start: {
                date: 2009-08-27 00:00:00
                timezone_type: 3
                timezone: America/New_York
            }
            end: {
                date: 2009-09-26 00:00:00
                timezone_type: 3
                timezone: America/New_York
            }
        }
        {
            start: {
                date: 2009-11-18 00:00:00
                timezone_type: 3
                timezone: America/New_York
            }
            end: {
                date: 2010-11-20 00:00:00
                timezone_type: 3
                timezone: America/New_York
            }
        }
        {
            start: {
                date: 2010-12-16 00:00:00
                timezone_type: 3
                timezone: America/New_York
            }
            end: {
                date: 2011-02-15 00:00:00
                timezone_type: 3
                timezone: America/New_York
            }
        }
        {
            start: {
                date: 2011-04-12 00:00:00
                timezone_type: 3
                timezone: America/New_York
            }
            end: {
                date: 2011-09-29 00:00:00
                timezone_type: 3
                timezone: America/New_York
            }
        }
        {
            start: {
                date: 2011-10-30 00:00:00
                timezone_type: 3
                timezone: America/New_York
            }
            end: {
                date: 2011-12-31 00:00:00
                timezone_type: 3
                timezone: America/New_York
            }
        }
        {
            start: {
                date: 2012-08-22 00:00:00
                timezone_type: 3
                timezone: America/New_York
            }
            end: {
                date: 2012-11-19 00:00:00
                timezone_type: 3
                timezone: America/New_York
            }
        }
        {
            start: {
                date: 2012-12-30 00:00:00
                timezone_type: 3
                timezone: America/New_York
            }
            end: {
                date: 2013-07-15 00:00:00
                timezone_type: 3
                timezone: America/New_York
            }
        }
        {
            start: {
                date: 2012-12-30 00:00:00
                timezone_type: 3
                timezone: America/New_York
            }
            end: {
                date: 2013-07-15 00:00:00
                timezone_type: 3
                timezone: America/New_York
            }
        }
    ]
}

```

}

A query I've been trying:

{  
"filtered" : {  
"query" : { "match\_all" : {}},  
"filter" : {  
"nested" : {  
"path" : "leases",  
"query" : {  
"bool" : {  
"must\_not" : [  
{  
"range" : {  
"leases.start" : {  
"from" : "2009-05-06 00:00:00",  
"to" : "2009-05-29 00:00:00",  
"include\_lower" : true,  
"include\_upper" : false  
}  
}  
},  
{  
"range" : {  
"leases.end" : {  
"from" : "2009-05-06 00:00:00",  
"to" : "2009-05-29 00:00:00",  
"include\_lower" : true,  
"include\_upper" : false  
}  
}  
}  
]  
}  
}  
}  
}  
}  
}

Any help would be greatly appreciated.

--

---

<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:** [July 6, 2017, 3:04am UTC](https://discuss.elastic.co/t/search-nested-collection-of-ranges/9681/2 "2017-07-06T03:04:42Z")

</div>


