Search in sources :

Example 1 with BulkIndexResponse

use of org.apache.storm.elasticsearch.response.BulkIndexResponse in project storm by apache.

the class EsState method updateState.

/**
 * Store current state to ElasticSearch.
 *
 * @param tuples list of tuples for storing to ES.
 *               Each tuple should have relevant fields (source, index, type, id) for EsState's tupleMapper to extract ES document.
 */
public void updateState(List<TridentTuple> tuples) {
    try {
        String bulkRequest = buildRequest(tuples);
        Response response = client.performRequest("post", "_bulk", new HashMap<>(), new StringEntity(bulkRequest.toString()));
        BulkIndexResponse bulkResponse = objectMapper.readValue(response.getEntity().getContent(), BulkIndexResponse.class);
        if (bulkResponse.hasErrors()) {
            LOG.warn("failed processing bulk index requests: " + bulkResponse.getFirstError() + ": " + bulkResponse.getFirstResult());
            throw new FailedException();
        }
    } catch (IOException e) {
        LOG.warn("failed processing bulk index requests: " + e.toString());
        throw new FailedException(e);
    }
}
Also used : BulkIndexResponse(org.apache.storm.elasticsearch.response.BulkIndexResponse) Response(org.elasticsearch.client.Response) StringEntity(org.apache.http.entity.StringEntity) BulkIndexResponse(org.apache.storm.elasticsearch.response.BulkIndexResponse) FailedException(org.apache.storm.topology.FailedException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 StringEntity (org.apache.http.entity.StringEntity)1 BulkIndexResponse (org.apache.storm.elasticsearch.response.BulkIndexResponse)1 FailedException (org.apache.storm.topology.FailedException)1 Response (org.elasticsearch.client.Response)1