Working with dates (availability/booking system)

Hi,

I’m planning to use Algolia to structure a Hotel like database. I saw that a lot of people had problems in the past on how to query for date availability with Algolia. Since we’re in the end of 2020 and the topics I’ve seen is from 2 years ago, have you already solved this kind of problem? Do you have a guide to structure our Indexes to query for available dates on records of booked dates?

Thank you very much.

Hi @dr1, to query or filter by dates you should convert the dates to a numeric value and use a numeric filter. Can you provide more information about your use case and how you are trying to query your data as well as more information about how your data is structured?

Thanks for the quick response. I’m using Firestore database that each document has info about check-in and check-out dates of each property. Let’s say:

{
  property_id: 1,
  check_in: date(2020,09,15),
  check_out: date(2021,09,15),
  ...
}

{
  property_id: 1,
  check_in: date(2021,09,20),
  check_out: date(2021,10,15),
  ...
}

{
  property_id: 2,
  check_in: date(2022,09,20),
  check_out: date(2022,10,15),
  ...
}

What I need is that the user could search for check-in and check-out dates that he’s planning and have a list in return of properties that do have availability for these days.

If he’s looking for check_in (2020, 09,16) and check_out (2020,09,18), the search will return both properties (1,2). If he searches for check_in (2021,09,16) and check_out (2021, 09, 30), the return will be only the property 2.

Above is a simple example, but I think this is a well-known kind of query, so maybe I don’t need to explain too much. If you need more info, feel free to ask, please. Thank you very much for the help.

Hi there,

I think that you’re referring to this post, right? In this case, it does indeed still applies today.

The booking use case is complex when it comes to Algolia because we’re a search engine. We prioritize speed and textual relevance, at the expense of exhaustivity and deeply complex querying capabilities. Additionally, because you need to index your data on our servers, you don’t have a real time system—you can get close, but there will always be a short window of time for data reconciliation when you send updates from your data source to Algolia.

We usually recommend going with other solutions for the booking use case. A database system will probably be more appropriate, even though it will be slower. This is a trade-off you likely want to make so that you can have 100% reliability in the availabilities, and a more advanced query language.