NikolaDai
(Bin Dai)
December 17, 2018, 2:20pm
1
i was trying to use bulkprocessor with java high level client. I copied the demo code in https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-document-bulk.html .However, it tells that it can't work and shows that there is no request added to bulkrequest. then i add one more line of codes as follows
bulkRequest.add(new IndexRequest("articles", "article", String.valueOf(j)).source(lineTxt, XContentType.JSON));
bulkProcessor.add(new IndexRequest("articles", "article", String.valueOf(j)).source(lineTxt, XContentType.JSON));
then it works. i dont why? it is supposed that only use bulkProcessor.add which will lead to the bulkRequest's addition of new request. Anyone helps?
dadoonet
(David Pilato)
December 17, 2018, 3:06pm
2
I'm not sure I understand the question or the problem.
Anyway, here is how I'm using the bulk processor:
Create bulk processor:
this.bulkProcessor = BulkProcessor.builder(
(request, bulkListener) -> esClient.bulkAsync(request, RequestOptions.DEFAULT, bulkListener),
new BulkProcessor.Listener() {
@Override
public void beforeBulk(long executionId, BulkRequest request) {
logger.debug("going to execute bulk of {} requests", request.numberOfActions());
}
@Override
public void afterBulk(long executionId, BulkRequest request, BulkResponse response) {
logger.debug("bulk executed {} failures", response.hasFailures() ? "with" : "without");
}
@Override
public void afterBulk(long executionId, BulkRequest request, Throwable failure) {
logger.warn("error while executing bulk", failure);
}
})
.setBulkActions(10000)
.setFlushInterval(TimeValue.timeValueSeconds(5))
.build();
Save a Java bean in elasticsearch:
public void save(Person person) throws JsonProcessingException {
byte[] bytes = mapper.writeValueAsBytes(person);
bulkProcessor.add(new IndexRequest("person", "_doc", person.idAsString()).source(bytes, XContentType.JSON));
}
Hoe this helps.
system
(system)
Closed
January 14, 2019, 3:06pm
3
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.