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 https://plus.google.com/108934389713447828932 http://www.facebook.com/AttacheCorporateHousing
https://twitter.com/#!/AttacheCorpHous http://www.linkedin.com/company/attache-property-management
http://www.yelp.com/biz/attache-property-management-washington
--