ES Java Bulk Timeout Error

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

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

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

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

Welcome to our community! :smiley:

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 :slight_smile:

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