private void writeToEsServer(Collection<EsMetricPayload> batch) {
        try {
            RestHighLevelClient client = getClient();
            BulkRequest request = new BulkRequest();
            for (EsMetricPayload metric : batch) {
                IndexRequest index = new IndexRequest(getIndexPrefix());
                index.source(JsonUtil.getObjectMapper().writeValueAsString(metric), XContentType.JSON);
                request.add(index);
            }

            ActionListener<BulkResponse> listener = new ActionListener<BulkResponse>() {
                @Override
                public void onResponse(BulkResponse bulkItemResponses) {
                    if (bulkItemResponses.hasFailures()) {
                        LOGGER.warn("Errors were reported when submitting bulk metrics into Elasticsearch. "
                                            + "This may have resulted in a loss of data: {0}", bulkItemResponses.buildFailureMessage());
                    }
                }

                @Override
                public void onFailure(Exception e) {
                    LOGGER.error("Failed to add metric(s) to Elasticsearch", e); //$NON-NLS-1$
                }
            };
            client.bulkAsync(request, RequestOptions.DEFAULT, listener);
        } catch (JsonProcessingException e) {
            LOGGER.error("Failed to add metric(s) to Elasticsearch", e); //$NON-NLS-1$
        }
    }
Process the next item in the queue.
gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/EsMetrics.java