Search in sources :

Example 1 with BulkResponseItem

use of org.opensearch.client.opensearch.core.bulk.BulkResponseItem in project opensearch-java by opensearch-project.

the class BulkResponse method serializeInternal.

protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
    generator.writeKey("errors");
    generator.write(this.errors);
    if (ApiTypeHelper.isDefined(this.items)) {
        generator.writeKey("items");
        generator.writeStartArray();
        for (BulkResponseItem item0 : this.items) {
            item0.serialize(generator, mapper);
        }
        generator.writeEnd();
    }
    generator.writeKey("took");
    generator.write(this.took);
    if (this.ingestTook != null) {
        generator.writeKey("ingest_took");
        generator.write(this.ingestTook);
    }
}
Also used : BulkResponseItem(org.opensearch.client.opensearch.core.bulk.BulkResponseItem)

Example 2 with BulkResponseItem

use of org.opensearch.client.opensearch.core.bulk.BulkResponseItem in project opensearch-java by opensearch-project.

the class CrudIT method validateBulkResponses.

private void validateBulkResponses(int nbItems, boolean[] errors, BulkResponse bulkResponse, BulkRequest bulkRequest) {
    for (int i = 0; i < nbItems; i++) {
        BulkResponseItem bulkResponseItem = bulkResponse.items().get(i);
        assertEquals("index", bulkResponseItem.index());
        assertEquals("_doc", bulkResponseItem.type());
        assertEquals(String.valueOf(i), bulkResponseItem.id());
        BulkOperation bulkOperation = bulkRequest.operations().get(i);
        if (bulkOperation.isIndex() || bulkOperation.isCreate()) {
            assertEquals(errors[i] ? 409 : 201, bulkResponseItem.status());
        } else if (bulkOperation.isUpdate()) {
            assertEquals(errors[i] ? Result.NotFound.jsonValue() : Result.Updated.jsonValue(), bulkResponseItem.result());
            assertEquals(errors[i] ? 404 : 200, bulkResponseItem.status());
        } else if (bulkOperation.isDelete()) {
            assertEquals(errors[i] ? Result.NotFound.jsonValue() : Result.Deleted.jsonValue(), bulkResponseItem.result());
            assertEquals(errors[i] ? 404 : 200, bulkResponseItem.status());
        }
    }
}
Also used : BulkResponseItem(org.opensearch.client.opensearch.core.bulk.BulkResponseItem) BulkOperation(org.opensearch.client.opensearch.core.bulk.BulkOperation)

Aggregations

BulkResponseItem (org.opensearch.client.opensearch.core.bulk.BulkResponseItem)2 BulkOperation (org.opensearch.client.opensearch.core.bulk.BulkOperation)1