Search in sources :

Example 1 with ErrorCause

use of org.opensearch.client.opensearch._types.ErrorCause in project opensearch-java by opensearch-project.

the class ListResponse method serializeInternal.

protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
    if (ApiTypeHelper.isDefined(this.nodeFailures)) {
        generator.writeKey("node_failures");
        generator.writeStartArray();
        for (ErrorCause item0 : this.nodeFailures) {
            item0.serialize(generator, mapper);
        }
        generator.writeEnd();
    }
    if (ApiTypeHelper.isDefined(this.nodes)) {
        generator.writeKey("nodes");
        generator.writeStartObject();
        for (Map.Entry<String, TaskExecutingNode> item0 : this.nodes.entrySet()) {
            generator.writeKey(item0.getKey());
            item0.getValue().serialize(generator, mapper);
        }
        generator.writeEnd();
    }
    if (ApiTypeHelper.isDefined(this.tasks)) {
        generator.writeKey("tasks");
        generator.writeStartObject();
        for (Map.Entry<String, Info> item0 : this.tasks.entrySet()) {
            generator.writeKey(item0.getKey());
            item0.getValue().serialize(generator, mapper);
        }
        generator.writeEnd();
    }
}
Also used : ErrorCause(org.opensearch.client.opensearch._types.ErrorCause) Map(java.util.Map)

Example 2 with ErrorCause

use of org.opensearch.client.opensearch._types.ErrorCause in project opensearch-java by opensearch-project.

the class BehaviorsTest method testAdditionalProperties.

@Test
public void testAdditionalProperties() {
    // Check that additional property map is initialized even if not set explicitly
    ErrorCause err = new ErrorCause.Builder().reason("Foo").type("Bar").build();
    assertEquals(0, err.metadata().size());
    err = new ErrorCause.Builder().reason("Some failure").type("Some type").metadata(MapBuilder.of("index", JsonData.of("test"), "retries", JsonData.of(1))).build();
    err = checkJsonRoundtrip(err, "{\"index\":\"test\",\"retries\":1,\"type\":\"Some type\",\"reason\":\"Some failure\"}");
    assertEquals("Some failure", err.reason());
    assertEquals(1, err.metadata().get("retries").to(int.class).intValue());
    assertEquals("test", err.metadata().get("index").to(String.class));
}
Also used : ErrorCause(org.opensearch.client.opensearch._types.ErrorCause) Test(org.junit.Test)

Example 3 with ErrorCause

use of org.opensearch.client.opensearch._types.ErrorCause in project core-ng-project by neowu.

the class ElasticSearchImpl method searchException.

// convert elasticsearch-java client exception, to append detailed error message
SearchException searchException(ElasticsearchException e) {
    ErrorCause causedBy = e.error().causedBy();
    var builder = new StringBuilder(e.getMessage());
    if (causedBy != null) {
        builder.append("\nreason: ").append(causedBy.reason());
    }
    return new SearchException(builder.toString(), e);
}
Also used : ErrorCause(co.elastic.clients.elasticsearch._types.ErrorCause) SearchException(core.framework.search.SearchException)

Example 4 with ErrorCause

use of org.opensearch.client.opensearch._types.ErrorCause in project core-ng-project by neowu.

the class ElasticSearchTypeImpl method validate.

private void validate(BulkResponse response) {
    if (!response.errors())
        return;
    var builder = new CodeBuilder();
    builder.append("bulk operation failed, errors=[\n");
    for (BulkResponseItem item : response.items()) {
        ErrorCause error = item.error();
        if (error != null) {
            builder.append("id={}, error={}, stackTrace={}\n", item.id(), error.reason(), error.stackTrace());
        }
    }
    builder.append("]");
    throw new SearchException(builder.build());
}
Also used : BulkResponseItem(co.elastic.clients.elasticsearch.core.bulk.BulkResponseItem) ErrorCause(co.elastic.clients.elasticsearch._types.ErrorCause) SearchException(core.framework.search.SearchException) CodeBuilder(core.framework.internal.asm.CodeBuilder)

Example 5 with ErrorCause

use of org.opensearch.client.opensearch._types.ErrorCause in project opensearch-java by opensearch-project.

the class CancelResponse method serializeInternal.

protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
    if (ApiTypeHelper.isDefined(this.nodeFailures)) {
        generator.writeKey("node_failures");
        generator.writeStartArray();
        for (ErrorCause item0 : this.nodeFailures) {
            item0.serialize(generator, mapper);
        }
        generator.writeEnd();
    }
    if (ApiTypeHelper.isDefined(this.nodes)) {
        generator.writeKey("nodes");
        generator.writeStartObject();
        for (Map.Entry<String, TaskExecutingNode> item0 : this.nodes.entrySet()) {
            generator.writeKey(item0.getKey());
            item0.getValue().serialize(generator, mapper);
        }
        generator.writeEnd();
    }
}
Also used : ErrorCause(org.opensearch.client.opensearch._types.ErrorCause) Map(java.util.Map)

Aggregations

ErrorCause (org.opensearch.client.opensearch._types.ErrorCause)3 ErrorCause (co.elastic.clients.elasticsearch._types.ErrorCause)2 SearchException (core.framework.search.SearchException)2 Map (java.util.Map)2 BulkResponseItem (co.elastic.clients.elasticsearch.core.bulk.BulkResponseItem)1 CodeBuilder (core.framework.internal.asm.CodeBuilder)1 Test (org.junit.Test)1