Search code examples
elasticsearchelasticsearch-py

How can i Filter an exists in a range like query?


I have an index with workingHour as an nested object that contains day, stat and end. class WorkingHourIndex(InnerDoc): day = Keyword() start = Date() end = Date()

Everything is indexed properly now when i search for documents i want to perform a query with day and a time and i want elasticsearch to check if the day exists of not and if it does , does the time exists between start and end.


Solution

  • something like this might work:

    day_query = Q('term', working_hours__day='DAY_I_NEED')
    time_query = Q('range', working_hours__start={'lt': TS}) & Q('range', working_hours__end={'gt': TS})
    Search().query('nested', path='working_hours', query=day_query & time_query)