本文整理汇总了Java中org.elasticsearch.action.bulk.BulkItemResponse.Failure方法的典型用法代码示例。如果您正苦于以下问题:Java BulkItemResponse.Failure方法的具体用法?Java BulkItemResponse.Failure怎么用?Java BulkItemResponse.Failure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.action.bulk.BulkItemResponse
的用法示例。
在下文中一共展示了BulkItemResponse.Failure方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testMergeConstructor
import org.elasticsearch.action.bulk.BulkItemResponse; //导入方法依赖的package包/类
public void testMergeConstructor() {
int mergeCount = between(2, 10);
List<BulkByScrollResponse> responses = new ArrayList<>(mergeCount);
int took = between(1000, 10000);
int tookIndex = between(0, mergeCount - 1);
List<BulkItemResponse.Failure> allBulkFailures = new ArrayList<>();
List<SearchFailure> allSearchFailures = new ArrayList<>();
boolean timedOut = false;
String reasonCancelled = rarely() ? randomAsciiOfLength(5) : null;
for (int i = 0; i < mergeCount; i++) {
// One of the merged responses gets the expected value for took, the others get a smaller value
TimeValue thisTook = timeValueMillis(i == tookIndex ? took : between(0, took));
// The actual status doesn't matter too much - we test merging those elsewhere
String thisReasonCancelled = rarely() ? randomAsciiOfLength(5) : null;
BulkByScrollTask.Status status = new BulkByScrollTask.Status(i, 0, 0, 0, 0, 0, 0, 0, 0, 0, timeValueMillis(0), 0f,
thisReasonCancelled, timeValueMillis(0));
List<BulkItemResponse.Failure> bulkFailures = frequently() ? emptyList()
: IntStream.range(0, between(1, 3)).mapToObj(j -> new BulkItemResponse.Failure("idx", "type", "id", new Exception()))
.collect(Collectors.toList());
allBulkFailures.addAll(bulkFailures);
List<SearchFailure> searchFailures = frequently() ? emptyList()
: IntStream.range(0, between(1, 3)).mapToObj(j -> new SearchFailure(new Exception())).collect(Collectors.toList());
allSearchFailures.addAll(searchFailures);
boolean thisTimedOut = rarely();
timedOut |= thisTimedOut;
responses.add(new BulkByScrollResponse(thisTook, status, bulkFailures, searchFailures, thisTimedOut));
}
BulkByScrollResponse merged = new BulkByScrollResponse(responses, reasonCancelled);
assertEquals(timeValueMillis(took), merged.getTook());
assertEquals(allBulkFailures, merged.getBulkFailures());
assertEquals(allSearchFailures, merged.getSearchFailures());
assertEquals(timedOut, merged.isTimedOut());
assertEquals(reasonCancelled, merged.getReasonCancelled());
}
示例2: getRespWithFailedDocument
import org.elasticsearch.action.bulk.BulkItemResponse; //导入方法依赖的package包/类
private BulkResponse getRespWithFailedDocument(RestStatus status) {
BulkResponse response = mock(BulkResponse.class);
when(response.hasFailures()).thenReturn(true);
BulkItemResponse itemResp = mock(BulkItemResponse.class);
when(itemResp.isFailed()).thenReturn(true);
BulkItemResponse.Failure failure = mock(BulkItemResponse.Failure.class);
when(failure.getStatus()).thenReturn(status);
when(itemResp.getFailure()).thenReturn(failure);
BulkItemResponse[] itemResponses = new BulkItemResponse[]{itemResp};
when(response.getItems()).thenReturn(itemResponses);
return response;
}
示例3: buildBulkItemFailure
import org.elasticsearch.action.bulk.BulkItemResponse; //导入方法依赖的package包/类
private BulkItemResponse buildBulkItemFailure(Exception e) {
BulkItemResponse itemResponse = mock(BulkItemResponse.class);
when(itemResponse.isFailed()).thenReturn(true);
BulkItemResponse.Failure failure = mock(BulkItemResponse.Failure.class);
when(itemResponse.getFailure()).thenReturn(failure);
when(failure.getCause()).thenReturn(e);
return itemResponse;
}
示例4: 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;
}
示例5: buildResponse
import org.elasticsearch.action.bulk.BulkItemResponse; //导入方法依赖的package包/类
/**
* Build the response for reindex actions.
*/
protected BulkByScrollResponse buildResponse(TimeValue took, List<BulkItemResponse.Failure> indexingFailures,
List<SearchFailure> searchFailures, boolean timedOut) {
return new BulkByScrollResponse(took, task.getStatus(), indexingFailures, searchFailures, timedOut);
}
示例6: 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());
}
}
}