# NullPointerException when using BulkRequestBuilder for bulk delete

**URL:** <https://discuss.elastic.co/t/nullpointerexception-when-using-bulkrequestbuilder-for-bulk-delete/47350>\
**Category:** Elasticsearch\
**Created:** [April 14, 2016, 6:13am UTC](https://discuss.elastic.co/t/nullpointerexception-when-using-bulkrequestbuilder-for-bulk-delete/47350 "2016-04-14T06:13:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fusio](https://avatars.discourse-cdn.com/v4/letter/f/839c29/32.png) [@fusio](https://discuss.elastic.co/u/fusio)\
**Post date:** [April 14, 2016, 6:13am UTC](https://discuss.elastic.co/t/nullpointerexception-when-using-bulkrequestbuilder-for-bulk-delete/47350/1 "2016-04-14T06:13:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [April 14, 2016, 9:12am UTC](https://discuss.elastic.co/t/nullpointerexception-when-using-bulkrequestbuilder-for-bulk-delete/47350/2 "2016-04-14T09:12:09Z")

</div>

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.

---

<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:** [July 5, 2017, 10:59pm UTC](https://discuss.elastic.co/t/nullpointerexception-when-using-bulkrequestbuilder-for-bulk-delete/47350/3 "2017-07-05T22:59:21Z")

</div>

Closed on July 5, 2017, 10:59pm UTC


