NullPointerException when using BulkRequestBuilder for bulk delete

Hi, I would like to delete the documents in an Index by Query.
First, I tried with DeleteByQueryRequestBuilder, but it is slow. How to improve the performance?

Then, I use BulkRequestBuilder, it is fast but t fails randomly by throwing NullPointerException. Why is it throwing the exception? I read from forum and turn of the refresh interval = -1, but it does not help.

I don't think the Elasticsearch forum is for code quality assistance, but in short terms, do not over-engineer your code with Arrays.stream(...).parallel().forEach() because BulkRequestBuilder is not threadsafe. Just use single thread to build a bulk request.