O
O
Oleg2018-01-26 18:31:00
elasticsearch
Oleg, 2018-01-26 18:31:00

Easticsearch how to filter by business hours?

Good afternoon. Can't filter organizations by opening hours.
There are such objects:

{
 { 
  id:10,
  business_hours : [
    {type:1,from:"0000", to:'0000'},
    {type:2,from:"0900", to:'2000'},
    {type:2,from:"0900", to:'2000'},
    {type:3,from:"0900", to:'2000'},
    .....
]
 }
}

Where type:
1 - around the clock
2 - open during the specified period
3 - closed
The first object in business_hours is about Monday, then about Tuesday, and so on.
I actually add this filter:
$filter = [
    'bool' => [
        'should' => [
            [
                ['term' => ['business_hours.0.type' => '1']], // круглосуточно
                [
                    'bool' => [
                        'must' => [
                            ['range' => ['business_hours.0.from' => ['lte' => '1000']]],
                            ['range' => ['business_hours.0.to' => ['gte' => '1200']]],
                            ['term' => ['business_hours.0.type' => 2]], // активно
                        ]
                    ],
                ]
            ]
        ]
    ]
];

I expect that this filter will take all objects that work around the clock
['term' => ['business_hours.0.type' => '1']], // круглосуточно

And all the objects that on Monday open before 10 am and close later than 12
But for some reason nothing is found. What am I doing wrong? Maybe you need to set up the index?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question