当前位置: 首页>>代码示例>>Java>>正文


Java ElasticSearchException.fromXContent方法代码示例

本文整理汇总了Java中org.elasticsearch.ElasticSearchException.fromXContent方法的典型用法代码示例。如果您正苦于以下问题:Java ElasticSearchException.fromXContent方法的具体用法?Java ElasticSearchException.fromXContent怎么用?Java ElasticSearchException.fromXContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.ElasticSearchException的用法示例。


在下文中一共展示了ElasticSearchException.fromXContent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fromXContent

import org.elasticsearch.ElasticSearchException; //导入方法依赖的package包/类
public static ShardSearchFailure fromXContent(XContentParser parser) throws IOException {
    XContentParser.Token token;
    ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.currentToken(), parser::getTokenLocation);
    String currentFieldName = null;
    int shardId = -1;
    String indexName = null;
    String nodeId = null;
    ElasticsearchException exception = null;
    while((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token.isValue()) {
            if (SHARD_FIELD.equals(currentFieldName)) {
                shardId  = parser.intValue();
            } else if (INDEX_FIELD.equals(currentFieldName)) {
                indexName  = parser.text();
            } else if (NODE_FIELD.equals(currentFieldName)) {
                nodeId  = parser.text();
            } else {
                throwUnknownField(currentFieldName, parser.getTokenLocation());
            }
        } else if (token == XContentParser.Token.START_OBJECT) {
            if (REASON_FIELD.equals(currentFieldName)) {
                exception = ElasticsearchException.fromXContent(parser);
            } else {
                throwUnknownField(currentFieldName, parser.getTokenLocation());
            }
        } else {
            throwUnknownToken(token, parser.getTokenLocation());
        }
    }
    return new ShardSearchFailure(exception,
            new SearchShardTarget(nodeId, new ShardId(new Index(indexName, IndexMetaData.INDEX_UUID_NA_VALUE), shardId)));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:35,代码来源:ShardSearchFailure.java

示例2: fromXContent

import org.elasticsearch.ElasticSearchException; //导入方法依赖的package包/类
public static Failure fromXContent(XContentParser parser) throws IOException {
    XContentParser.Token token = parser.currentToken();
    ensureExpectedToken(XContentParser.Token.START_OBJECT, token, parser::getTokenLocation);

    String shardIndex = null, nodeId = null;
    int shardId = -1;
    boolean primary = false;
    RestStatus status = null;
    ElasticsearchException reason = null;

    String currentFieldName = null;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token.isValue()) {
            if (_INDEX.equals(currentFieldName)) {
                shardIndex = parser.text();
            } else if (_SHARD.equals(currentFieldName)) {
                shardId = parser.intValue();
            } else if (_NODE.equals(currentFieldName)) {
                nodeId = parser.text();
            } else if (STATUS.equals(currentFieldName)) {
                status = RestStatus.valueOf(parser.text());
            } else if (PRIMARY.equals(currentFieldName)) {
                primary = parser.booleanValue();
            } else {
                throwUnknownField(currentFieldName, parser.getTokenLocation());
            }
        } else if (token == XContentParser.Token.START_OBJECT) {
            if (REASON.equals(currentFieldName)) {
                reason = ElasticsearchException.fromXContent(parser);
            } else {
                throwUnknownField(currentFieldName, parser.getTokenLocation());
            }
        }
    }
    return new Failure(new ShardId(shardIndex, IndexMetaData.INDEX_UUID_NA_VALUE, shardId), nodeId, reason, status, primary);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:39,代码来源:ReplicationResponse.java

示例3: testToAndFromXContent

import org.elasticsearch.ElasticSearchException; //导入方法依赖的package包/类
public void testToAndFromXContent() throws IOException {
    final XContent xContent = randomFrom(XContentType.values()).xContent();

    ShardSearchFailure[] shardSearchFailures = new ShardSearchFailure[randomIntBetween(1, 5)];
    for (int i = 0; i < shardSearchFailures.length; i++) {
        Exception cause = randomFrom(
                new ParsingException(1, 2, "foobar", null),
                new InvalidIndexTemplateException("foo", "bar"),
                new TimestampParsingException("foo", null),
                new NullPointerException()
        );
        shardSearchFailures[i] = new  ShardSearchFailure(cause, new SearchShardTarget("node_" + i, new Index("test", "_na_"), i));
    }

    final String phase = randomFrom("query", "search", "other");
    SearchPhaseExecutionException actual = new SearchPhaseExecutionException(phase, "unexpected failures", shardSearchFailures);

    BytesReference exceptionBytes = XContentHelper.toXContent(actual, xContent.type(), randomBoolean());

    ElasticsearchException parsedException;
    try (XContentParser parser = createParser(xContent, exceptionBytes)) {
        assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken());
        parsedException = ElasticsearchException.fromXContent(parser);
        assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken());
        assertNull(parser.nextToken());
    }

    assertNotNull(parsedException);
    assertThat(parsedException.getHeaderKeys(), hasSize(0));
    assertThat(parsedException.getMetadataKeys(), hasSize(1));
    assertThat(parsedException.getMetadata("es.phase"), hasItem(phase));
    // SearchPhaseExecutionException has no cause field
    assertNull(parsedException.getCause());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:35,代码来源:SearchPhaseExecutionExceptionTests.java

示例4: fromXContent

import org.elasticsearch.ElasticSearchException; //导入方法依赖的package包/类
/**
 * Reads a {@link BulkItemResponse} from a {@link XContentParser}.
 *
 * @param parser the {@link XContentParser}
 * @param id the id to assign to the parsed {@link BulkItemResponse}. It is usually the index of
 *           the item in the {@link BulkResponse#getItems} array.
 */
public static BulkItemResponse fromXContent(XContentParser parser, int id) throws IOException {
    ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.currentToken(), parser::getTokenLocation);

    XContentParser.Token token = parser.nextToken();
    ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser::getTokenLocation);

    String currentFieldName = parser.currentName();
    token = parser.nextToken();

    final OpType opType = OpType.fromString(currentFieldName);
    ensureExpectedToken(XContentParser.Token.START_OBJECT, token, parser::getTokenLocation);

    DocWriteResponse.Builder builder = null;
    CheckedConsumer<XContentParser, IOException> itemParser = null;

    if (opType == OpType.INDEX || opType == OpType.CREATE) {
        final IndexResponse.Builder indexResponseBuilder = new IndexResponse.Builder();
        builder = indexResponseBuilder;
        itemParser = (indexParser) -> IndexResponse.parseXContentFields(indexParser, indexResponseBuilder);

    } else if (opType == OpType.UPDATE) {
        final UpdateResponse.Builder updateResponseBuilder = new UpdateResponse.Builder();
        builder = updateResponseBuilder;
        itemParser = (updateParser) -> UpdateResponse.parseXContentFields(updateParser, updateResponseBuilder);

    } else if (opType == OpType.DELETE) {
        final DeleteResponse.Builder deleteResponseBuilder = new DeleteResponse.Builder();
        builder = deleteResponseBuilder;
        itemParser = (deleteParser) -> DeleteResponse.parseXContentFields(deleteParser, deleteResponseBuilder);
    } else {
        throwUnknownField(currentFieldName, parser.getTokenLocation());
    }

    RestStatus status = null;
    ElasticsearchException exception = null;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        }

        if (ERROR.equals(currentFieldName)) {
            if (token == XContentParser.Token.START_OBJECT) {
                exception = ElasticsearchException.fromXContent(parser);
            }
        } else if (STATUS.equals(currentFieldName)) {
            if (token == XContentParser.Token.VALUE_NUMBER) {
                status = RestStatus.fromCode(parser.intValue());
            }
        } else {
            itemParser.accept(parser);
        }
    }

    ensureExpectedToken(XContentParser.Token.END_OBJECT, token, parser::getTokenLocation);
    token = parser.nextToken();
    ensureExpectedToken(XContentParser.Token.END_OBJECT, token, parser::getTokenLocation);

    BulkItemResponse bulkItemResponse;
    if (exception != null) {
        Failure failure = new Failure(builder.getShardId().getIndexName(), builder.getType(), builder.getId(), exception, status);
        bulkItemResponse = new BulkItemResponse(id, opType, failure);
    } else {
        bulkItemResponse = new BulkItemResponse(id, opType, builder.build());
    }
    return bulkItemResponse;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:74,代码来源:BulkItemResponse.java


注:本文中的org.elasticsearch.ElasticSearchException.fromXContent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。