Jacobian Jacobian - 1 month ago 17
PHP Question

'id cannot be null.' error when trying to delete from ElasticSearch

I have

ElasticSearch 5.0.0
and a standard
client for
, that I installed using composer. Everything works ok, except delete operation. I can not delete by query and as a result get this error message:

Uncaught exception
'Elasticsearch\Common\Exceptions\InvalidArgumentException' with
message 'id cannot be null.'

This is how I try to delete:

$client = ClientBuilder::create()->build();
$params = [
'index' => 'layers'
'type' => 'layers_type'
'body' => [
'bool' => [
'should' => [
'multi_match' => [
'query' => ["304"],
'fields' => ["id"] // not a surrogate _id, by my own id, that is a part of my index properties

So, how can I fix it? Do I need to install any plugin and if yes, how can I do that on my Windows machine?

Val Val

The delete function requires an id since it is meant to delete a single document, that's the reason why you get that error.

In order to do what you want, you need the deleteByQuery function instead, but it has been removed in 2.x and not added back (yet).

You can use the Elastica PHP client in the meantime. It is 5.0 compliant and supports the deleteByQuery feature.