# Search nested collection of date ranges

**URL:** https://discuss.elastic.co/t/search-nested-collection-of-date-ranges/9680
**Category:** Elasticsearch
**Created:** [November 12, 2012, 7:45pm UTC](https://discuss.elastic.co/t/search-nested-collection-of-date-ranges/9680 "2012-11-12T19:45:36Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Johnny\_Peck](https://avatars.discourse-cdn.com/v4/letter/j/b5a626/32.png) [@Johnny\_Peck](https://discuss.elastic.co/u/Johnny_Peck)
#### Post date: [November 12, 2012, 7:45pm UTC](https://discuss.elastic.co/t/search-nested-collection-of-date-ranges/9680/1 "2012-11-12T19:45: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.

--  
[http://g.co/maps/q49hq](http://g.co/maps/q49hq)[https://plus.google.com/108934389713447828932](https://plus.google.com/108934389713447828932) [http://www.facebook.com/AttacheCorporateHousing](http://www.facebook.com/AttacheCorporateHousing)  
[https://twitter.com/#!/AttacheCorpHous](https://twitter.com/#!/AttacheCorpHous) [http://www.linkedin.com/company/attache-property-management](http://www.linkedin.com/company/attache-property-management)  
[http://www.yelp.com/biz/attache-property-management-washington](http://www.yelp.com/biz/attache-property-management-washington)

--

---

<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-date-ranges/9680/2 "2017-07-06T03:04:42Z")

</div>


