Connection to Elastic Search server is not consistant

I'm facing some strange issue. I'm trying to load one record into Elastic search server. The programs work fine sometimes and sometimes it is failing with java.net.ConnectionException. Not sure what is causing the problem.

            BulkProcessor.Listener listener = new BulkProcessor.Listener() {
            @Override
            public void beforeBulk(long executionId, BulkRequest request) {
                int numberOfActions = request.numberOfActions();
                logger.info("Executing bulk [{}] with {} requests", executionId, numberOfActions);
            }

            @Override
            public void afterBulk(long executionId, BulkRequest request, BulkResponse response) {
                if (response.hasFailures()) {
                    logger.warn("Bulk [{}] executed with failures: ", executionId);

                    for (int i = 0; i < response.getItems().length; i++) {
                        BulkItemResponse item = response.getItems()[i];
                        if (item.isFailed()) {
                            IndexRequest ireq = (IndexRequest) request.requests().get(i);
                            logger.info("Failed while indexing to " + item.getIndex() + " type " + item.getType() + " " +
                                    "request: [" + ireq + "]: [" + item.getFailureMessage() + "]");
                        }
                    }

                } else {
                    logger.error("Bulk [{}] completed in {} milliseconds", executionId, response.getTook().getMillis());
                }
            }

            @Override
            public void afterBulk(long executionId, BulkRequest request, Throwable failure) {
                logger.error("Failed to execute bulk", failure);
            }
        };

        RestHighLevelClient elasticsearchClient = new RestHighLevelClient(RestClient.builder(new HttpHost(esURL, esPort, transportSchema)));
         bulkProcessor = BulkProcessor.builder(
                (request, bulkListener) -> elasticsearchClient.bulkAsync(request, bulkListener), listener)
                .setBulkActions(50)
                .setBulkSize(new ByteSizeValue(1, ByteSizeUnit.MB))
                .setConcurrentRequests(2)
                .setFlushInterval(TimeValue.timeValueSeconds(5))
                .setBackoffPolicy(BackoffPolicy
                        .constantBackoff(TimeValue.timeValueSeconds(100), 3)).build();

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