use of org.elasticsearch.client.Response 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);
}
}
use of org.elasticsearch.client.Response 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);
}
}
use of org.elasticsearch.client.Response in project graylog2-server by Graylog2.
the class PlainJsonApi method perform.
public JsonNode perform(Request request, String errorMessage) {
return client.execute((c, requestOptions) -> {
request.setOptions(requestOptions);
final Response response = c.getLowLevelClient().performRequest(request);
return objectMapper.readTree(response.getEntity().getContent());
}, errorMessage);
}
use of org.elasticsearch.client.Response in project graylog2-server by Graylog2.
the class ClientES7 method existingIndices.
private String[] existingIndices() {
final Request request = new Request("GET", "/_cat/indices");
request.addParameter("format", "json");
request.addParameter("h", "index");
final JsonNode jsonResponse = client.execute((c, requestOptions) -> {
request.setOptions(requestOptions);
final Response response = c.getLowLevelClient().performRequest(request);
return objectMapper.readTree(response.getEntity().getContent());
});
return Streams.stream(jsonResponse.elements()).map(index -> index.path("index").asText()).distinct().toArray(String[]::new);
}
use of org.elasticsearch.client.Response in project graylog2-server by Graylog2.
the class ClientES7 method getMapping.
private Map<String, String> getMapping(String index) {
final Request request = new Request("GET", "/" + index + "/_mapping");
final JsonNode response = client.execute((c, requestOptions) -> {
request.setOptions(requestOptions);
final Response result = c.getLowLevelClient().performRequest(request);
return objectMapper.readTree(result.getEntity().getContent());
});
return extractFieldMappings(index, response).collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().path("type").asText()));
}
Aggregations