简体   繁体   中英

Include 'NULL' values in filter along with range filter in Elastica

I'm using Elastica and I need to create the filter that will get NULL values along with values that lower than 100.

For now my code looks like this:

$this->filter = $qb->query()->bool();
$this->filter->addShould($qb->query()->range('price', ['lte' => 100]));

It returns data with price lower than 100. I also need to get data with null values. So far I tried:

$this->filter->addMustNot($qb->query()->exists('price')); // returns 0 items
$this->filter->addShould($qb->query()->missing('price')); // doesn't work. Gives undefined query "missing" in Facade.php

Could someone help me with this issue? Or how to fix the problem with undefined query "missing" or to create another filter that will fit my needs. Thanks.

Used same range() to make it work how I need. So it looks like this:

$this->filter->addMustNot($qb->query()->range('price', ['gte' => 100]));

I'm using addMustNot so it filters all values that matches that filter (everything less than 100 will be returned, even if it's null value).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM