當前位置: 首頁>>代碼示例>>Java>>正文


Java BulkItemResponse.getFailure方法代碼示例

本文整理匯總了Java中org.elasticsearch.action.bulk.BulkItemResponse.getFailure方法的典型用法代碼示例。如果您正苦於以下問題:Java BulkItemResponse.getFailure方法的具體用法?Java BulkItemResponse.getFailure怎麽用?Java BulkItemResponse.getFailure使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.elasticsearch.action.bulk.BulkItemResponse的用法示例。


在下文中一共展示了BulkItemResponse.getFailure方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: put

import org.elasticsearch.action.bulk.BulkItemResponse; //導入方法依賴的package包/類
@Override
public List<IndexResponse> put(List<Document> documents) {
    final Stopwatch watch = LoggingUtils.createStopWatch();
    final List<IndexResponse> results = new ArrayList<>();
    final BulkRequestBuilder bulkRequest = client.prepareBulk();
    for (final Document document : documents) {
        final String original = document.get_jsonObject();
        final String source = addPlatformFields(document.get_id(), original, document.getVisibility());
        if (source != null) {
            bulkRequest.add(
                    client.prepareIndex(indexName, document.get_type(), document.get_id()).setSource(
                            source));
        }
    }
    for (final BulkItemResponse response : bulkRequest.get()) {
        final IndexResponse indexResponse;
        if (response.isFailed()) {
            final BulkItemResponse.Failure failure = response.getFailure();
            logger.warn(
                    "Indexing failed on an object ({}, {}): {}", response.getId(), response.getType(),
                    response.getFailureMessage());
            indexResponse = convertElasticResponse(failure.getId(), failure.getType(), -1, false);
        } else {
            final org.elasticsearch.action.index.IndexResponse ir = response.getResponse();
            indexResponse = convertElasticResponse(ir.getId(), ir.getType(), ir.getVersion(), true);
        }
        results.add(indexResponse);
    }

    LoggingUtils.stopAndLogStopWatch(logger, watch, "Put Documents");

    if (forceRefreshOnInsert) {
        logger.trace("Forcing index refresh");
        forceIndexRefresh();
    }

    return results;
}
 
開發者ID:ezbake,項目名稱:ezelastic,代碼行數:39,代碼來源:ElasticClient.java

示例2: flushBulk

import org.elasticsearch.action.bulk.BulkItemResponse; //導入方法依賴的package包/類
private void flushBulk() {
	BulkResponse bulkResponse = bulkRequest.execute().actionGet(); // flush
	if (bulkResponse.hasFailures()) { // log failures
		for (BulkItemResponse r : bulkResponse.getItems()) {
			LOG.error(r.getFailureMessage());
			Failure failure = r.getFailure();
			// e.g. when ES server is overloaded
			throw new ElasticsearchException(failure.toString());
		}
	}
}
 
開發者ID:BlueBrain,項目名稱:bluima,代碼行數:12,代碼來源:ElasticIndexer.java

示例3: testBulkWithIngestFailures

import org.elasticsearch.action.bulk.BulkItemResponse; //導入方法依賴的package包/類
public void testBulkWithIngestFailures() throws Exception {
    createIndex("index");

    BytesReference source = jsonBuilder().startObject()
        .field("description", "my_pipeline")
        .startArray("processors")
        .startObject()
        .startObject("test")
        .endObject()
        .endObject()
        .endArray()
        .endObject().bytes();
    PutPipelineRequest putPipelineRequest = new PutPipelineRequest("_id", source, XContentType.JSON);
    client().admin().cluster().putPipeline(putPipelineRequest).get();

    int numRequests = scaledRandomIntBetween(32, 128);
    BulkRequest bulkRequest = new BulkRequest();
    for (int i = 0; i < numRequests; i++) {
        IndexRequest indexRequest = new IndexRequest("index", "type", Integer.toString(i)).setPipeline("_id");
        indexRequest.source(Requests.INDEX_CONTENT_TYPE, "field", "value", "fail", i % 2 == 0);
        bulkRequest.add(indexRequest);
    }

    BulkResponse response = client().bulk(bulkRequest).actionGet();
    assertThat(response.getItems().length, equalTo(bulkRequest.requests().size()));
    for (int i = 0; i < bulkRequest.requests().size(); i++) {
        BulkItemResponse itemResponse = response.getItems()[i];
        if (i % 2 == 0) {
            BulkItemResponse.Failure failure = itemResponse.getFailure();
            ElasticsearchException compoundProcessorException = (ElasticsearchException) failure.getCause();
            assertThat(compoundProcessorException.getRootCause().getMessage(), equalTo("test processor failed"));
        } else {
            IndexResponse indexResponse = itemResponse.getResponse();
            assertThat("Expected a successful response but found failure [" + itemResponse.getFailure() + "].",
                itemResponse.isFailed(), is(false));
            assertThat(indexResponse, notNullValue());
            assertThat(indexResponse.getId(), equalTo(Integer.toString(i)));
            assertEquals(DocWriteResponse.Result.CREATED, indexResponse.getResult());
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:42,代碼來源:IngestClientIT.java


注:本文中的org.elasticsearch.action.bulk.BulkItemResponse.getFailure方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。