本文整理汇总了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;
}
示例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());
}
}
}
示例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());
}
}
}