简体   繁体   English

在过滤器中包括'NULL'值,在Elastica中包括范围过滤器

[英]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. 我使用的是Elastica,我需要创建一个过滤器,该过滤器将获取NULL值以及小于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. 它返回价格低于100的数据。我还需要获取具有值的数据。 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. 使用相同的range()使它按我的需要工作。 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). 我正在使用addMustNot,因此它会过滤与该过滤器匹配的所有值(即使返回的值是null ,也将返回小于100的所有值)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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