use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkRequest in project incubator-inlong by apache.
the class TestEsCallbackListener method testBeforeBulk.
/**
* testBeforeBulk
*/
@Test
public void testBeforeBulk() {
// prepare
ProfileEvent event = TestEsSinkContext.mockProfileEvent();
EsIndexRequest indexRequest = context.getIndexRequestHandler().parse(context, event);
long executionId = 0;
BulkRequest bulkRequest = new BulkRequest();
bulkRequest.add(indexRequest);
// test
EsCallbackListener listener = new EsCallbackListener(context);
listener.beforeBulk(executionId, bulkRequest);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkRequest in project Zpider by zeroized.
the class ElasticClient method bulkIndex.
public List<String> bulkIndex(List<DataEntity> docs) throws IOException {
BulkRequest bulkRequest = new BulkRequest();
for (DataEntity doc : docs) {
IndexRequest indexRequest = new IndexRequest(doc.getIndexId(), "doc", doc.getId());
indexRequest.source(doc.getData());
bulkRequest.add(indexRequest);
}
BulkResponse bulkResponse = highLevelClient.bulk(bulkRequest);
return Arrays.stream(bulkResponse.getItems()).map(BulkItemResponse::getId).collect(Collectors.toList());
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkRequest in project Zpider by zeroized.
the class ElasticClient method bulkIndex.
public List<String> bulkIndex(List<Map<String, ?>> docs, String index) throws IOException {
BulkRequest bulkRequest = new BulkRequest();
for (Map<String, ?> doc : docs) {
IndexRequest indexRequest = new IndexRequest(index, "doc");
indexRequest.source(doc);
bulkRequest.add(indexRequest);
}
BulkResponse bulkResponse = highLevelClient.bulk(bulkRequest);
return Arrays.stream(bulkResponse.getItems()).map(BulkItemResponse::getId).collect(Collectors.toList());
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkRequest in project vertx-zero by silentbalanceyh.
the class AbstractEsClient method doBatch.
protected Boolean doBatch(final JsonArray documents, final String idField, final Supplier<BulkRequest> executor) {
if (Ut.isNil(documents)) {
/*
* No data, not needed
*/
return true;
} else {
final RestHighLevelClient client = this.client();
boolean result;
try {
final BulkRequest request = executor.get();
final BulkResponse bulkResponse = client.bulk(request, RequestOptions.DEFAULT);
if (bulkResponse.hasFailures()) {
this.logger().warn("Failure found: {0}", bulkResponse.buildFailureMessage());
result = false;
} else {
this.logger().info("Documents have been indexed ( size = {0} ) successfully!", documents.size());
result = true;
}
} catch (final IOException ioe) {
this.logger().jvm(ioe);
result = false;
}
this.helper.closeClient(client);
return result;
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkRequest in project vertx-zero by silentbalanceyh.
the class EsAmbitUpdate method process.
@Override
public Boolean process(final JsonArray documents, final String idField) {
return this.doBatch(documents, idField, () -> {
final BulkRequest request = new BulkRequest();
Ut.itJArray(documents).forEach(json -> {
final String documentId = json.getString(idField);
if (Ut.notNil(documentId)) {
final UpdateRequest indexRequest = new UpdateRequest().index(this.index).id(documentId).doc(this.toDocument(json));
request.add(indexRequest);
}
});
return request;
});
}
Aggregations