Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Plastic/Elasticsearch-搜索具有空值的条目_Php_Laravel_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Laravel 5.2 - Fatal编程技术网 elasticsearch,laravel-5.2,Php,Laravel,elasticsearch,Laravel 5.2" /> elasticsearch,laravel-5.2,Php,Laravel,elasticsearch,Laravel 5.2" />

Php Plastic/Elasticsearch-搜索具有空值的条目

Php Plastic/Elasticsearch-搜索具有空值的条目,php,laravel,elasticsearch,laravel-5.2,Php,Laravel,elasticsearch,Laravel 5.2,我使用的是Laravel5.2,它有一个名为job_-ads的表。job_-ads表有一个type列,有时为null。我想搜索所有类型为null的招聘广告,但如果我尝试 App\JobAd::search()->term('type', null)->sortBy("id", "ASC")->get()->totalHits(); 通过php artisan tinker,我得到 Elasticsearch\Common\Exceptions\BadRequest400

我使用的是Laravel5.2,它有一个名为job_-ads的表。job_-ads表有一个type列,有时为null。我想搜索所有类型为null的招聘广告,但如果我尝试

App\JobAd::search()->term('type', null)->sortBy("id", "ASC")->get()->totalHits();
通过php artisan tinker,我得到

Elasticsearch\Common\Exceptions\BadRequest400Exception with message 'query_parsing_exception: No value specified for term query'
我看了elasticsearch文档,但没有发现我的错误。我使用的是elasticsearch 2.4。

您需要使用inside must not子句。它基本上是一个(在2.2.0中已弃用)查找空值的函数

{
  "query": {
    "bool": {
      "must_not": {
        "exists": {
          "field": "type"
        }
      }
    }
  }
}
我没有使用塑料,但它应该很容易转换。从查询结果来看,它应该类似于下面的查询

App\JobAd::search()->mustNot()->exists('type')->sortBy("id", "ASC")->get()->totalHits();

希望有帮助

我刚刚读到关于丢失的查询的信息,所以我的思路是正确的:)您的代码可以正常工作,谢谢!很高兴我能帮忙!