use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkRequest in project vind by RBMHTechnology.
the class BulkRequestBuilder method executeBulk.
public static BulkResponse executeBulk(BulkRequest bulkRequest, RequestOptions options, String indexName, RestHighLevelClient client) throws IOException {
ActionRequestValidationException validationException = bulkRequest.validate();
if (validationException != null && validationException.validationErrors().isEmpty() == false) {
throw validationException;
}
Request req = toRequest(bulkRequest, indexName);
req.setOptions(options);
Response response;
try {
response = client.getLowLevelClient().performRequest(req);
} catch (ResponseException e) {
throw new IOException("Indexing was not successful", e);
}
try {
return client.parseEntity(response.getEntity(), BulkResponse::fromXContent);
} catch (Exception e) {
throw new IOException("Unable to parse response body for " + response, e);
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkRequest in project vind by RBMHTechnology.
the class ElasticVindClient method add.
public BulkResponse add(Map<String, Object> jsonDoc) throws IOException {
final BulkRequest bulkIndexRequest = new BulkRequest(defaultIndex);
bulkIndexRequest.add(ElasticRequestUtils.getIndexRequest(jsonDoc));
bulkIndexRequest.timeout(TimeValue.timeValueMillis(connectionTimeout));
bulkIndexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
return BulkRequestBuilder.executeBulk(bulkIndexRequest, RequestOptions.DEFAULT, defaultIndex, client);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkRequest in project phoebus-olog by Olog.
the class LogbookRepository method saveAll.
@Override
public <S extends Logbook> Iterable<S> saveAll(Iterable<S> logbooks) {
BulkRequest bulk = new BulkRequest();
logbooks.forEach(logbook -> {
try {
bulk.add(new IndexRequest(ES_LOGBOOK_INDEX, ES_LOGBOOK_TYPE, logbook.getName()).source(mapper.writeValueAsBytes(logbook), XContentType.JSON));
} catch (JsonProcessingException e) {
logger.log(Level.SEVERE, "Failed to create logbook: " + logbook, e);
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Failed to create logbook: " + logbook);
}
});
bulk.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
BulkResponse bulkResponse;
try {
bulkResponse = client.bulk(bulk, RequestOptions.DEFAULT);
if (bulkResponse.hasFailures()) {
// process failures by iterating through each bulk response item
bulkResponse.forEach(response -> {
if (response.getFailure() != null) {
logger.log(Level.SEVERE, response.getFailureMessage(), response.getFailure().getCause());
}
});
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Failed to create logbooks: " + logbooks);
} else {
return logbooks;
}
} catch (IOException e) {
logger.log(Level.SEVERE, "Failed to create logbooks: " + logbooks, e);
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Failed to create logbooks: " + logbooks);
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkRequest in project phoebus-olog by Olog.
the class PropertyRepositoryIT method cleanupProperties.
/**
* Clean up the properties
*
* @param properties
*/
private void cleanupProperties(List<Property> properties) {
try {
BulkRequest bulk = new BulkRequest();
properties.forEach(property -> {
bulk.add(new DeleteRequest(ES_PROPERTY_INDEX, ES_PROPERTY_TYPE, property.getName()));
});
client.bulk(bulk, RequestOptions.DEFAULT);
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkRequest in project phoebus-olog by Olog.
the class LogbookRepositoryIT method cleanupLogbook.
/**
* Cleanup up the logbooks
*
* @param logbooks
* @throws IOException
*/
void cleanupLogbook(List<Logbook> logbooks) throws IOException {
// Manual cleanup since Olog does not delete things
BulkRequest bulk = new BulkRequest();
logbooks.forEach(logbook -> {
bulk.add(new DeleteRequest(ES_LOGBOOK_INDEX, ES_LOGBOOK_TYPE, logbook.getName()));
});
client.bulk(bulk, RequestOptions.DEFAULT);
}
Aggregations