Hi,
I'm working on a booking application using elasticsearch for search &
filtering.
Basically each document describes a service, such as an educational
class. And each class has multiple date or datetime blocks during
which it is available.
For example, the class "1-day Argentine Tango entry level class in
Brooklyn" could be available in the following blocks:
8/9/11 to 8/11/11 (so the class is available in 3 different days: 8/9,
8/10, 8/11)
8/15/11 to 8/15/11 (meaning just 1 single day)
8/17/11 to 8/21/11
And the class "1-hour Physics 101 tutorial" could be available in the
following blocks:
8/5/11 2pm - 5pm (so the slots 2pm to 3pm, 3 to 4, 4 to 5 are open)
8/7/11 9am - 12pm
A users might search for "Physics tutorial" and want to filter the
results to those that are available between 8/5/11 3pm to 8/5/11 5pm.
What's the best way to implement such search/filtering in ES?
- I suppose a simple way is to index the class description multiple
times, once for each available block. So for the class "1-day
Argentine Tango entry level class in Brooklyn" above, 3 documents
would be indexed. They all have the text "1-day Argentine Tango entry
level class in Brooklyn" as description. The 1st document would have
startdate: "2011-8-5"
enddate:"2011-8-11"
The 2nd, 3rd documents would also have the appropriate startdate &
enddate.
And when I want to search for classes between the 8/7 and 8/9, I could
just add the filter:
"range" : {
"startdate" : {
"lte" : "2011-8-7"
}
"enddate" : {
"gte" : "2011-8-9"
}
}
The problem with this approach is I have to repeat the description
many times. So if a class is available in 100 blocks, I'd have to
index 100 separate documents each have the same description. Is there
a better way?
- How do I index and filter on datetime such as "8/5/11 2pm"? Is
there a "datetime" field type?
Thanks.