I have items for rent. The User specifies a start_date
and end_date
. Every item has multiple blocked_periods
also with start and end date.
Goal:
Query all available items. Lets say: 12.11., 13.11., 14.11., 15.11.
Blocked are 13. and 14.
The item should be available on 12. or 15. or from 12. until 15. but start and end date can't be on 13. and 14.
Current Index:
{
"development_items" : {
"aliases" : { },
"mappings" : {
"item" : {
"properties" : {
"blocked_periods" : {
"type" : "nested",
"properties" : {
"end_date" : {
"type" : "date",
"format" : "yyyy-MM-dd"
},
"start_date" : {
"type" : "date",
"format" : "yyyy-MM-dd"
}
}
}
}
}
},
"settings" : {
"index" : {
"creation_date" : "1503327829680",
"number_of_shards" : "5",
"number_of_replicas" : "1",
"uuid" : "9b9BhF-ITta2dlCKRLrnfA",
"version" : {
"created" : "2040499"
}
}
},
"warmers" : { }
}
}
Current Query:
{
bool: {
must_not: {
nested: {
path: 'blocked_periods',
query: {
bool: {
should: [
{
bool: {
must: [
{
range: {
'blocked_periods.start_date': {
lte: start_date
}
}
},
{
range: {
'blocked_periods.end_date': {
gte: end_date
}
}
}
]
}
}
]
}
}
}
}
}
}