I am trying to store hotel room availability in elasticsearch. And then I need to
search rooms those are available from a date till another date. I have come up with
two ways to store data for availability, and they are as follows:
Here availability dictionary store all dates and value of each date key is true of false, representing its available on
that day or not.
{
"_id": "khg2uo47tyhgjwebu7624787",
"room_type": "garden view",
"hotel_name": "Cool hotel",
"hotel_id": "jytu64r982u0299023",
"room_metadata1": 233,
"room_color": "black",
"availability": {
"2016-07-01": true,
"2016-07-02": true,
"2016-07-03": false,
"2016-07-04": true,
"2016-07-05": true,
"2016-07-06": null,
"2016-07-07": true,
"2016-07-08": true,
----
----
for 365 days
}
}
Here availability array only stores those dates when room is available
{
"_id": "khg2uo47tyhgjwebu7624787",
"room_type": "garden view",
"hotel_name": "Cool hotel",
"hotel_id": "jytu64r982u0299023",
"room_metadata1": 535,
"room_color": "black",
"availability": ["2016-07-01", "2016-07-02", "2016-07-04", "2016-07-05", "2016-07-07", "2016-07-08"] ---for 365 days
}
}
I want to search all rooms, those are available from from_date
till to_date
and that should look into availability
dictionary or array. And my date range may span up to 365 days (e.g. 2016-01-01 to 2016-12-31)
Question 1) How to store these availability data , so that I can perform the above search easily?
Question 2) I could not find any way to search through range of dates, so any suggestion?
Please note, items
in availability
may not be kept sorted. And I may have more than 100 million records to search through.