# Bulk ingester no close at the end

**URL:** <https://discuss.elastic.co/t/bulk-ingester-no-close-at-the-end/329633>\
**Category:** Elasticsearch\
**Created:** [April 10, 2023, 4:01am UTC](https://discuss.elastic.co/t/bulk-ingester-no-close-at-the-end/329633 "2023-04-10T04:01:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ALX\_DM](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alx_dm/32/106314_2.png) [@ALX\_DM](https://discuss.elastic.co/u/ALX_DM)\
**Post date:** [April 10, 2023, 4:01am UTC](https://discuss.elastic.co/t/bulk-ingester-no-close-at-the-end/329633/1 "2023-04-10T04:01:34Z")

</div>

I read the documents but it is not clear to me.

I have this code:

```auto
public void indexProduct(Product product) {
try (BulkIngester<String> bulkIngester = indexingService.createBulkIngester()) {
      indexingService.bulkIngestWithAsset(product, bulkIngester);
    } catch (InterruptedException e) {
      throw new RuntimeException(e);
    }
}

for((int i=0; i<10; i++) {

   indexProduct(product[i]);

}

```

Then I will not close.

Is this ok?

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [April 10, 2023, 5:54am UTC](https://discuss.elastic.co/t/bulk-ingester-no-close-at-the-end/329633/2 "2023-04-10T05:54:44Z")

</div>

Hi @ALX_DM

You should check if the resource implements java.lang.AutoCloseable, if yes the resource will be closed as soon as the try-catch block is executed.

---

<div class="post-metadata">

**Author:** ![ALX\_DM](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alx_dm/32/106314_2.png) [@ALX\_DM](https://discuss.elastic.co/u/ALX_DM)\
**Post date:** [April 11, 2023, 5:17am UTC](https://discuss.elastic.co/t/bulk-ingester-no-close-at-the-end/329633/3 "2023-04-11T05:17:38Z")

</div>

> [@RabBit\_BR](#):
>
> source implements java.lang.AutoClosea

Hi, the resource does not implement java.lang.AutoCloseable

Is it same as BulkProcessor wherein you have `.awaitclose()`

And BulkIngester have `.close()` only

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [April 11, 2023, 12:11pm UTC](https://discuss.elastic.co/t/bulk-ingester-no-close-at-the-end/329633/4 "2023-04-11T12:11:49Z")

</div>

In this case, it is better to make the .close explicit.

---

<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:** [May 9, 2023, 12:12pm UTC](https://discuss.elastic.co/t/bulk-ingester-no-close-at-the-end/329633/5 "2023-05-09T12:12:11Z")

</div>

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