# ES Java Bulk Timeout Error

**URL:** <https://discuss.elastic.co/t/es-java-bulk-timeout-error/311533>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [August 5, 2022, 1:04pm UTC](https://discuss.elastic.co/t/es-java-bulk-timeout-error/311533 "2022-08-05T13:04:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sriram\_R](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sriram_r/32/100359_2.png) [@Sriram\_R](https://discuss.elastic.co/u/Sriram_R)\
**Post date:** [August 5, 2022, 1:04pm UTC](https://discuss.elastic.co/t/es-java-bulk-timeout-error/311533/1 "2022-08-05T13:04:44Z")

</div>

I'm trying to index docs in bulk for some reason I keep getting a timeout exception. However when I try to index a single document, it works perfectly.

Here's the code for indexing a single document

```auto
Reader reader = new StringReader(jsonString);
IndexRequest<JsonData> request = IndexRequest.of(i -> i.index(indexName).withJson(reader));
        esClient.index(request).whenComplete((response, exception) ->
        {
            if (exception != null)
            {
                System.out.println("Exception = " + exception);
                exception.printStackTrace();
            }
        });

```

Here's the code for BulkRequests

```auto
BulkRequest.Builder builder = new BulkRequest.Builder();
builder.timeout(Time.of(time -> time.time("2m")));

JsonpMapper jsonpMapper = logManager.getMapper();
JsonProvider jsonProvider = jsonpMapper.jsonProvider();

for (EsLog log: logs) {
           String logJson;
           try {
                logJson = mapper.writeValueAsString(log);
            } catch (JsonProcessingException e) {
                e.printStackTrace();
                logJson = "{}";
            }
            Reader reader = new StringReader(logJson);
            builder.operations(
                    op -> op.index(
                            idx -> idx.index(indexName)
                                    .id(UUID.randomUUID().toString())
                                    .document(JsonData.from(jsonProvider.createParser(reader), jsonpMapper))
                    )
            );
        }

        esClient.bulk(builder.build()).whenComplete(((bulkResponse, exception) -> {
            if (exception != null) {
                System.out.println("Exception : " + exception.getMessage());
                exception.printStackTrace();
            } else {
                for (BulkResponseItem res: bulkResponse.items()) {
                    System.out.println("=====");
                    System.out.println(res.result());
                    System.out.println(res.index());
                    System.out.println(res.id());
                    System.out.println("=====");
                }
            }
        }));

```

I had some errors using the POJO, so I followed the solution from here for bulk requests

> [@Java 8.1 bulk request](https://discuss.elastic.co/t/java-8-1-bulk-request/302423/7):
>
> Well, I finally get it with following code wink String json = "my\_json\_value"; Reader reader = new StringReader(json); JsonpMapper jsonpMapper = getClient().\_transport().jsonpMapper(); JsonProvider jsonProvider = jsonpMapper.jsonProvider(); JsonData jd = JsonData.from(jsonProvider.createParser(reader), jsonpMapper); BulkRequest.Builder br = new BulkRequest.Builder(); br.operations(op -\> op.index(idx -\> idx.index(index).id(id).document(jd))); BulkRequest request = br.build(); BulkResponse r…

The code to index a single document works properly but the bulk index code throws a timeout exception.

 ![Screenshot 2022-08-05 at 6.33.30 PM](https://us1.discourse-cdn.com/elastic/original/3X/9/6/968ca9ee95f10935df91badc99f29e91cee528a7.png)

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [August 8, 2022, 11:59pm UTC](https://discuss.elastic.co/t/es-java-bulk-timeout-error/311533/2 "2022-08-08T23:59:59Z")

</div>

Welcome to our community! 😃

Please don't post pictures of text, logs or code. They are difficult to read, impossible to search and replicate (if it's code), and some people may not be even able to see them 🙂

---

<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:** [September 6, 2022, 12:00am UTC](https://discuss.elastic.co/t/es-java-bulk-timeout-error/311533/3 "2022-09-06T00:00:29Z")

</div>

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