Search in sources :

Example 1 with PercolateResponse

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

the class EsPercolateBolt method process.

/**
 * {@inheritDoc}
 * Tuple should have relevant fields (source, index, type) for storeMapper to extract ES document.<br/>
 * If there exists non-empty percolate response, EsPercolateBolt will emit tuple with original source
 * and Percolate.Match for each Percolate.Match in PercolateResponse.
 */
@Override
public void process(Tuple tuple) {
    try {
        String source = tupleMapper.getSource(tuple);
        String index = tupleMapper.getIndex(tuple);
        String type = tupleMapper.getType(tuple);
        Map<String, String> indexParams = new HashMap<>();
        indexParams.put(type, null);
        String percolateDoc = "{\"doc\": " + source + "}";
        Response response = client.performRequest("get", getEndpoint(index, type, "_percolate"), new HashMap<>(), new StringEntity(percolateDoc));
        PercolateResponse percolateResponse = objectMapper.readValue(response.getEntity().getContent(), PercolateResponse.class);
        if (!percolateResponse.getMatches().isEmpty()) {
            for (PercolateResponse.Match match : percolateResponse.getMatches()) {
                collector.emit(new Values(source, match));
            }
        }
        collector.ack(tuple);
    } catch (Exception e) {
        collector.reportError(e);
        collector.fail(tuple);
    }
}
Also used : PercolateResponse(org.apache.storm.elasticsearch.response.PercolateResponse) Response(org.elasticsearch.client.Response) StringEntity(org.apache.http.entity.StringEntity) HashMap(java.util.HashMap) Values(org.apache.storm.tuple.Values) PercolateResponse(org.apache.storm.elasticsearch.response.PercolateResponse)

Aggregations

HashMap (java.util.HashMap)1 StringEntity (org.apache.http.entity.StringEntity)1 PercolateResponse (org.apache.storm.elasticsearch.response.PercolateResponse)1 Values (org.apache.storm.tuple.Values)1 Response (org.elasticsearch.client.Response)1