Hi I'm a bit confused on how to perform a bulk request with the new Java API client.
To index one document I use the following code that works without problems. Since we are using GSON I pass the json string representation of the document in a StringReader (country.toESJsonReader()):
IndexResponse indexResponse = elasticSearch.getESClient().index(builder ->
builder
.index(aliasName)
.id(country.id())
.withJson(country.toESJsonReader())
.waitForActiveShards(asBuilder -> asBuilder.count(1))
.refresh(Refresh.True));
When indexing multiple documents I use the following code that throws the following exception:
"Class class co.elastic.clients.Elasticsearch.core.bulk.CreateOperation cannot be read from JSON"
// Create bulk request.
BulkRequest.Builder bulkRequestBuilder = new BulkRequest.Builder()
.waitForActiveShards(asBuilder -> asBuilder.count(1))
.refresh(Refresh.True);
// Add countries to bulk request.
List<BulkOperation> bulkOperations = new ArrayList<>();
for (Country country : countries) {
bulkOperations.add(new CreateOperation.Builder<String>()
.index(aliasName)
.id(country.id())
.withJson(country.toESJsonReader())
.build()
._toBulkOperation());
}
bulkRequestBuilder.operations(bulkOperations);
// Perform bulk request.
BulkResponse bulkResponse = elasticSearch.getESClient().bulk(bulkRequestBuilder.build());
Any idea what I am doing wrong here?
Thanks