# Is BulkIngester (replacement of 'Bulk Processor') in elasticsearch java api thread safe?

**URL:** <https://discuss.elastic.co/t/is-bulkingester-replacement-of-bulk-processor-in-elasticsearch-java-api-thread-safe/344285>\
**Category:** Elasticsearch\
**Created:** [October 3, 2023, 6:26am UTC](https://discuss.elastic.co/t/is-bulkingester-replacement-of-bulk-processor-in-elasticsearch-java-api-thread-safe/344285 "2023-10-03T06:26:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Irfanulla](https://avatars.discourse-cdn.com/v4/letter/i/f9ae1b/32.png) [@Irfanulla](https://discuss.elastic.co/u/Irfanulla)\
**Post date:** [October 3, 2023, 6:26am UTC](https://discuss.elastic.co/t/is-bulkingester-replacement-of-bulk-processor-in-elasticsearch-java-api-thread-safe/344285/1 "2023-10-03T06:26:02Z")

</div>

**Use case:** I have multiple kafka listeners for various topics. Each topic Listener will run in multiple threads (using spring's 'ConcurrentKafkaListenerContainer'). Listeners will be performing Update/Insert operations on Elasticsearch via its Java client (newer low-level client). I realized that performing bulk operations is very performant and hence will be do that. Also found that the client library provides a very good utility called 'BulkIngester'(replacement of 'Bulk Processor' in previous versions) which is exactly what I needed.

**Query** : Since multiple thread will be adding update/insert operations to 'BulkIngester', I would like to understand if it is thread safe? As its user, do I need to take care of any synchronization?

Also, I did go through the 'BulkIngester' code and functionally understood how it is working. It also has code to perform synchronization but couldn't fully wrap my head around it.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 3, 2023, 11:37am UTC](https://discuss.elastic.co/t/is-bulkingester-replacement-of-bulk-processor-in-elasticsearch-java-api-thread-safe/344285/2 "2023-10-03T11:37:19Z")

</div>

Welcome!

Yes. You can use it the same way you were using the BulkProcessor.

Small usage example here:

> <https://github.com/dadoonet/elasticsearch-java-client-demo/blob/main/src/test/java/fr/pilato/test/elasticsearch/hlclient/EsClientIT.java#L338-L377>

AFAICS in the code, it's using an internal synchronisation so it's safe to use the same instance from multiple threads:

> <https://github.com/elastic/elasticsearch-java/blob/23973026f0780d62b18d618321c27a24cdb8a4c3/java-client/src/main/java/co/elastic/clients/elasticsearch/_helpers/bulk/BulkIngester.java#L73-L77>

---

<div class="post-metadata">

**Author:** ![Irfanulla](https://avatars.discourse-cdn.com/v4/letter/i/f9ae1b/32.png) [@Irfanulla](https://discuss.elastic.co/u/Irfanulla)\
**Post date:** [October 4, 2023, 7:12am UTC](https://discuss.elastic.co/t/is-bulkingester-replacement-of-bulk-processor-in-elasticsearch-java-api-thread-safe/344285/3 "2023-10-04T07:12:35Z")

</div>

Thanks very much David for clarification.

Looks like the Java concurrency - Locks are being used, that are more flexible and sophisticated thread synchronization mechanism.

---

<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:** [November 1, 2023, 7:12am UTC](https://discuss.elastic.co/t/is-bulkingester-replacement-of-bulk-processor-in-elasticsearch-java-api-thread-safe/344285/4 "2023-11-01T07:12:48Z")

</div>

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