# How to pass null filter in elastic search + PHP

**URL:** <https://discuss.elastic.co/t/how-to-pass-null-filter-in-elastic-search-php/106172>\
**Category:** Elasticsearch\
**Created:** [November 2, 2017, 10:37am UTC](https://discuss.elastic.co/t/how-to-pass-null-filter-in-elastic-search-php/106172 "2017-11-02T10:37:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sanjay25](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sanjay25](https://discuss.elastic.co/u/sanjay25)\
**Post date:** [November 2, 2017, 10:37am UTC](https://discuss.elastic.co/t/how-to-pass-null-filter-in-elastic-search-php/106172/1 "2017-11-02T10:37:56Z")

</div>

I want to filter search result. I want to search that if 'manuf\_id' is not specified than is should return all records. I also want to put AND condition in term. below is my search query in elastic.

below is my code.

```
$params = [
            'index' => $this->client->getIndex(),
            'type' => $this->client->getType(),
			"from" => $from, "size" => $productPerPage,
			'body' => [
           "query" => [
			   "bool" => [
				  "must" => [
					 [
						  "multi_match" => [
							  "fields" => ["prod_name", "prod_seo_name"],
							  "type" => "phrase_prefix",
							  "query" => 'samsung'
						  ]
					 ],
						//$conditionArr
					 [
						  "term"=> ["manuf_id"=>null]
					 ]
				  ]
			   ]
			]
			],
       ];

```

Above query is not running. is there something I am missing? ANy help would be great.

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [November 20, 2017, 7:38pm UTC](https://discuss.elastic.co/t/how-to-pass-null-filter-in-elastic-search-php/106172/2 "2017-11-20T19:38:34Z")

</div>

You can't search for `null` directly, since Elasticsearch doesn't store null values. Instead, you'll have to use an Existing query ([https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html)) inside of a `must_not` clause of a boolean. E.g. you're asking if the field does not exist on the document.

If you need to differentiate between missing fields and null fields, you'll need to use `null_value` property: [https://www.elastic.co/guide/en/elasticsearch/reference/current/null-value.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/null-value.html)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 18, 2017, 7:38pm UTC](https://discuss.elastic.co/t/how-to-pass-null-filter-in-elastic-search-php/106172/3 "2017-12-18T19:38:51Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
