I have an index for businesses in Elasticsearch. Each document in the index represent a business, and each business has business_hours. I'm trying to allow a filter on the business hours using the day of the week and the time. For example,we'd like to be able to do a filter for show we all business that are open Tuesday Evenings after 6:00PM I'm thinking that we should have a field with the following mappings:
{
"mappings": {
"properties": {
"business_hours": {
"type": "date_range",
"format": "w'T'hh:mma"
}
}
}
}
Each document would then have an array of business_hours. So a store that is open on Monday 9:00AM - 5:00PM, and Tuesday 9:30AM - 5:00PM would look like this:
POST my-index/_doc
{
"name": "My Store",
"business_hours": [
{
"gte": "1T09:00AM",
"lte": "1T05:00PM"
},
{
"gte": "2T09:30AM",
"lte": "2T05:00PM"
}
]
}
I tried to search this document and query for it, but the filter for the hours is not working, they look like theyre getting ignored.... Does Elasticsearch support filtering by a day of the week or does it need to be an actual datetime?
Here's the query I used. Its supposed to filter for business open on Wednesday but it returned the document above which only had business hours on Monday and Tuesday
GET my-index/_search
{
"query": {
"bool": {
"filter": [
{
"range": {
"business_hours": {
"gte": "3T10:00AM",
"lte": "3T05:00PM",
"relation": "CONTAINS"
}
}
}
]
}
}
}