use of co.elastic.clients.elasticsearch.core.bulk.OperationType in project elasticsearch-java by elastic.
the class RequestTest method testBulkRequest.
@Test
public void testBulkRequest() throws IOException {
AppData appData = new AppData();
appData.setIntValue(42);
appData.setMsg("Some message");
BulkResponse bulk = client.bulk(_0 -> _0.operations(_1 -> _1.create(_2 -> _2.index("foo").id("abc").document(appData))).operations(_1 -> _1.create(_2 -> _2.index("foo").id("def").document(appData))).operations(_1 -> _1.update(_2 -> _2.index("foo").id("gh").action(_3 -> _3.docAsUpsert(true).doc(appData)))));
assertFalse(bulk.errors());
assertEquals(3, bulk.items().size());
assertEquals(OperationType.Create, bulk.items().get(0).operationType());
assertEquals("foo", bulk.items().get(0).index());
assertEquals(1L, bulk.items().get(0).version().longValue());
assertEquals("foo", bulk.items().get(1).index());
assertEquals(1L, bulk.items().get(1).version().longValue());
assertEquals(42, client.get(b -> b.index("foo").id("gh"), AppData.class).source().intValue);
}
Aggregations