Cannot use ignore_unavailable in DeleteRequest in Elasticsearch Java API Client

I am using the official Java API Client for Elasticsearch. : Introduction | Elasticsearch Java API Client [7.17] | Elastic

When deleting I cannot use ignore_unavailable

elasticsearchClient
        .delete(idx -> idx.index(indexName()).id(getId()))

The Java doc also not showing ignore_unavailable .
(DeleteRequest (java-client 7.17.23 API))

but looks more options are supported in Search Request:
(SearchRequest (java-client 7.17.23 API))

How can I use ignore_unavailable in DeleteRequest with the new Elasticsearch Java API Client ?

Are you looking for _delete_by_query, which has that setting? DeleteByQueryRequest (java-client 7.17.23 API)

Or what are you trying to do that a delete request for a single ID would make sense for ignore_unavailable (you‘re only targeting a single primary shard here)? Though you can set how many replicas need to be available for the command to succeed.

Thanks @xeraa
I am trying to delete one document in one index. And the index possibly does not exist. So I would like to use iguore_unavailable to bypass the error.

I think ignore_unavailable bypasses the error if the index does not exist, not shard.

This parameter is not part of the Delete API | Elasticsearch Guide [8.15] | Elastic. To make sure it was not a documentation issue, I tested in Kibana Dev Tools and got this error: request contains unrecognized parameter: [ignore_unavailable]. Since it's not accepted, the Java client (or any other Elasticsearch client) does not expose it.

Have you considered ignoring the error on the client side? Since you can only delete one document with this API.

I do not think that is the case. The purpose of the parameter is to allow partial results when multiple shards are addressed. A delete request is routed to a single shard based on the document id or routing value so a partial result is never possible. It therefore as far as I can see makes no sense to support the parameter here. I would recommend you instead handle the exception.

1 Like

Thank you @Quentin_Pradet and @Christian_Dahlqvist
That helps me understand it more deeply.