How to pass null filter in elastic search + PHP

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.

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) 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

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