@Test
public void testCountBulkErrors() {

	AtomicInteger errors = new AtomicInteger();
	elasticsearchClient.getHttpClient().send("POST", elasticsearchUrl + "/_bulk", CONTENT_TYPE_NDJSON, os ->
			os.write(("{ \"index\" : { \"_index\" : \"test\", \"_type\" : \"type1\", \"_id\" : \"1\" } }\n" +
					"{ \"field1\" : \"value1\" }\n" +
					"{ \"update\" : {\"_id\" : \"42\", \"_type\" : \"type1\", \"_index\" : \"index1\"} }\n" +
					"{ \"doc\" : {\"field\" : \"value\"} }\n"
			).getBytes("UTF-8")), new ElasticsearchClient.BulkErrorCountingResponseHandler() {
		@Override
		public void onBulkError(int errorCount) {
			errors.set(errorCount);
		}
	});
	assertThat(errors.get()).isEqualTo(1);
}