The best way to do this is to use nested documents.
First: set up your mapping to indicate that the hours document should be treated as nested:
curl -XPUT 'http://127.0.0.1:9200/foo/?pretty=1' -d ' { "mappings" : { "location" : { "properties" : { "hours" : { "include_in_root" : 1, "type" : "nested", "properties" : { "open" : { "type" : "short" }, "close" : { "type" : "short" }, "day" : { "index" : "not_analyzed", "type" : "string" } } }, "name" : { "type" : "string" } } } } } '
Add some data: (pay attention to several values โโfor hours of operation)
curl -XPOST 'http://127.0.0.1:9200/foo/location?pretty=1' -d ' { "name" : "Test", "hours" : [ { "open" : 9, "close" : 12, "day" : "monday" }, { "open" : 13, "close" : 17, "day" : "monday" } ] } '
Then run your query, filtering the current day and time:
curl -XGET 'http://127.0.0.1:9200/foo/location/_search?pretty=1' -d ' { "query" : { "filtered" : { "query" : { "text" : { "name" : "test" } }, "filter" : { "nested" : { "path" : "hours", "filter" : { "and" : [ { "term" : { "hours.day" : "monday" } }, { "range" : { "hours.close" : { "gte" : 10 } } }, { "range" : { "hours.open" : { "lte" : 10 } } } ] } } } } } } '
That should work.
Unfortunately, at 0.17.5 it throws NPE - this is most likely a simple bug that will be fixed in the near future. I discovered a problem for this: https://github.com/elasticsearch/elasticsearch/issues/1263
UPDATE Unusually, now I can not replicate NPE - this query works correctly both in version 0.17.5 and higher. There must have been a temporary glitch.
Clint