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);
}
}
Aggregations