Search in sources :

Example 1 with OperationType

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);
}
Also used : CreateIndexResponse(co.elastic.clients.elasticsearch.indices.CreateIndexResponse) SearchResponse(co.elastic.clients.elasticsearch.core.SearchResponse) BeforeClass(org.junit.BeforeClass) RequestItem(co.elastic.clients.elasticsearch.core.msearch.RequestItem) CompletableFuture(java.util.concurrent.CompletableFuture) IndexState(co.elastic.clients.elasticsearch.indices.IndexState) BooleanResponse(co.elastic.clients.transport.endpoints.BooleanResponse) DateTime(co.elastic.clients.util.DateTime) Map(java.util.Map) OperationType(co.elastic.clients.elasticsearch.core.bulk.OperationType) ModelTestCase(co.elastic.clients.elasticsearch.model.ModelTestCase) Property(co.elastic.clients.elasticsearch._types.mapping.Property) Refresh(co.elastic.clients.elasticsearch._types.Refresh) ElasticsearchException(co.elastic.clients.elasticsearch._types.ElasticsearchException) HistogramAggregate(co.elastic.clients.elasticsearch._types.aggregations.HistogramAggregate) NodesResponse(co.elastic.clients.elasticsearch.cat.NodesResponse) GetResponse(co.elastic.clients.elasticsearch.core.GetResponse) ElasticsearchTestServer(co.elastic.clients.elasticsearch.ElasticsearchTestServer) Test(org.junit.Test) IOException(java.io.IOException) GetIndexResponse(co.elastic.clients.elasticsearch.indices.GetIndexResponse) Instant(java.time.Instant) GetIndicesSettingsResponse(co.elastic.clients.elasticsearch.indices.GetIndicesSettingsResponse) GetMappingResponse(co.elastic.clients.elasticsearch.indices.GetMappingResponse) MsearchResponse(co.elastic.clients.elasticsearch.core.MsearchResponse) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) ClosePointInTimeResponse(co.elastic.clients.elasticsearch.core.ClosePointInTimeResponse) DateTimeFormatter(java.time.format.DateTimeFormatter) BulkResponse(co.elastic.clients.elasticsearch.core.BulkResponse) ElasticsearchClient(co.elastic.clients.elasticsearch.ElasticsearchClient) DiskUsageResponse(co.elastic.clients.elasticsearch.indices.DiskUsageResponse) ClearScrollResponse(co.elastic.clients.elasticsearch.core.ClearScrollResponse) Assert(org.junit.Assert) Collections(java.util.Collections) IndexResponse(co.elastic.clients.elasticsearch.core.IndexResponse) ElasticsearchAsyncClient(co.elastic.clients.elasticsearch.ElasticsearchAsyncClient) BulkResponse(co.elastic.clients.elasticsearch.core.BulkResponse) Test(org.junit.Test)

Aggregations

ElasticsearchAsyncClient (co.elastic.clients.elasticsearch.ElasticsearchAsyncClient)1 ElasticsearchClient (co.elastic.clients.elasticsearch.ElasticsearchClient)1 ElasticsearchTestServer (co.elastic.clients.elasticsearch.ElasticsearchTestServer)1 ElasticsearchException (co.elastic.clients.elasticsearch._types.ElasticsearchException)1 Refresh (co.elastic.clients.elasticsearch._types.Refresh)1 HistogramAggregate (co.elastic.clients.elasticsearch._types.aggregations.HistogramAggregate)1 Property (co.elastic.clients.elasticsearch._types.mapping.Property)1 NodesResponse (co.elastic.clients.elasticsearch.cat.NodesResponse)1 BulkResponse (co.elastic.clients.elasticsearch.core.BulkResponse)1 ClearScrollResponse (co.elastic.clients.elasticsearch.core.ClearScrollResponse)1 ClosePointInTimeResponse (co.elastic.clients.elasticsearch.core.ClosePointInTimeResponse)1 GetResponse (co.elastic.clients.elasticsearch.core.GetResponse)1 IndexResponse (co.elastic.clients.elasticsearch.core.IndexResponse)1 MsearchResponse (co.elastic.clients.elasticsearch.core.MsearchResponse)1 SearchResponse (co.elastic.clients.elasticsearch.core.SearchResponse)1 OperationType (co.elastic.clients.elasticsearch.core.bulk.OperationType)1 RequestItem (co.elastic.clients.elasticsearch.core.msearch.RequestItem)1 CreateIndexResponse (co.elastic.clients.elasticsearch.indices.CreateIndexResponse)1 DiskUsageResponse (co.elastic.clients.elasticsearch.indices.DiskUsageResponse)1 GetIndexResponse (co.elastic.clients.elasticsearch.indices.GetIndexResponse)1