Java 8.1 bulk request

Well, I finally get it with following code :wink:

String json = "my_json_value";
Reader reader = new StringReader(json);

JsonpMapper jsonpMapper = getClient()._transport().jsonpMapper();
JsonProvider jsonProvider = jsonpMapper.jsonProvider();
JsonData jd = JsonData.from(jsonProvider.createParser(reader), jsonpMapper);

BulkRequest.Builder br = new BulkRequest.Builder();
br.operations(op -> op.index(idx -> idx.index(index).id(id).document(jd)));

BulkRequest request = br.build();
BulkResponse response = getClient().bulk(request);
3 Likes