Search in sources :

Example 1 with SearchFailure

use of org.elasticsearch.action.bulk.byscroll.ScrollableHitSource.SearchFailure in project elasticsearch by elastic.

the class BulkByScrollResponse method toXContent.

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.field("took", took.millis());
    builder.field("timed_out", timedOut);
    status.innerXContent(builder, params);
    builder.startArray("failures");
    for (Failure failure : bulkFailures) {
        builder.startObject();
        failure.toXContent(builder, params);
        builder.endObject();
    }
    for (SearchFailure failure : searchFailures) {
        failure.toXContent(builder, params);
    }
    builder.endArray();
    return builder;
}
Also used : SearchFailure(org.elasticsearch.action.bulk.byscroll.ScrollableHitSource.SearchFailure) SearchFailure(org.elasticsearch.action.bulk.byscroll.ScrollableHitSource.SearchFailure) Failure(org.elasticsearch.action.bulk.BulkItemResponse.Failure)

Example 2 with SearchFailure

use of org.elasticsearch.action.bulk.byscroll.ScrollableHitSource.SearchFailure in project elasticsearch by elastic.

the class BulkByScrollResponseTests method assertResponseEquals.

private void assertResponseEquals(BulkByScrollResponse expected, BulkByScrollResponse actual) {
    assertEquals(expected.getTook(), actual.getTook());
    BulkByScrollTaskStatusTests.assertTaskStatusEquals(Version.CURRENT, expected.getStatus(), actual.getStatus());
    assertEquals(expected.getBulkFailures().size(), actual.getBulkFailures().size());
    for (int i = 0; i < expected.getBulkFailures().size(); i++) {
        Failure expectedFailure = expected.getBulkFailures().get(i);
        Failure actualFailure = actual.getBulkFailures().get(i);
        assertEquals(expectedFailure.getIndex(), actualFailure.getIndex());
        assertEquals(expectedFailure.getType(), actualFailure.getType());
        assertEquals(expectedFailure.getId(), actualFailure.getId());
        assertEquals(expectedFailure.getMessage(), actualFailure.getMessage());
        assertEquals(expectedFailure.getStatus(), actualFailure.getStatus());
    }
    assertEquals(expected.getSearchFailures().size(), actual.getSearchFailures().size());
    for (int i = 0; i < expected.getSearchFailures().size(); i++) {
        SearchFailure expectedFailure = expected.getSearchFailures().get(i);
        SearchFailure actualFailure = actual.getSearchFailures().get(i);
        assertEquals(expectedFailure.getIndex(), actualFailure.getIndex());
        assertEquals(expectedFailure.getShardId(), actualFailure.getShardId());
        assertEquals(expectedFailure.getNodeId(), actualFailure.getNodeId());
        assertEquals(expectedFailure.getReason().getClass(), actualFailure.getReason().getClass());
        assertEquals(expectedFailure.getReason().getMessage(), actualFailure.getReason().getMessage());
    }
}
Also used : SearchFailure(org.elasticsearch.action.bulk.byscroll.ScrollableHitSource.SearchFailure) SearchFailure(org.elasticsearch.action.bulk.byscroll.ScrollableHitSource.SearchFailure) Failure(org.elasticsearch.action.bulk.BulkItemResponse.Failure)

Example 3 with SearchFailure

use of org.elasticsearch.action.bulk.byscroll.ScrollableHitSource.SearchFailure in project elasticsearch by elastic.

the class AsyncBulkByScrollActionTests method testShardFailuresAbortRequest.

/**
     * Mimicks shard search failures usually caused by the data node serving the
     * scroll request going down.
     */
public void testShardFailuresAbortRequest() throws Exception {
    SearchFailure shardFailure = new SearchFailure(new RuntimeException("test"));
    ScrollableHitSource.Response scrollResponse = new ScrollableHitSource.Response(false, singletonList(shardFailure), 0, emptyList(), null);
    simulateScrollResponse(new DummyAsyncBulkByScrollAction(), timeValueNanos(System.nanoTime()), 0, scrollResponse);
    BulkByScrollResponse response = listener.get();
    assertThat(response.getBulkFailures(), empty());
    assertThat(response.getSearchFailures(), contains(shardFailure));
    assertFalse(response.isTimedOut());
    assertNull(response.getReasonCancelled());
    assertThat(client.scrollsCleared, contains(scrollId));
}
Also used : UpdateResponse(org.elasticsearch.action.update.UpdateResponse) SearchResponse(org.elasticsearch.action.search.SearchResponse) DeleteResponse(org.elasticsearch.action.delete.DeleteResponse) BulkItemResponse(org.elasticsearch.action.bulk.BulkItemResponse) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) ClearScrollResponse(org.elasticsearch.action.search.ClearScrollResponse) IndexResponse(org.elasticsearch.action.index.IndexResponse) InternalSearchResponse(org.elasticsearch.search.internal.InternalSearchResponse) ActionResponse(org.elasticsearch.action.ActionResponse) DocWriteResponse(org.elasticsearch.action.DocWriteResponse) ShardSearchFailure(org.elasticsearch.action.search.ShardSearchFailure) SearchFailure(org.elasticsearch.action.bulk.byscroll.ScrollableHitSource.SearchFailure)

Example 4 with SearchFailure

use of org.elasticsearch.action.bulk.byscroll.ScrollableHitSource.SearchFailure in project elasticsearch by elastic.

the class BulkByScrollResponseTests method randomSearchFailures.

private List<SearchFailure> randomSearchFailures() {
    if (randomBoolean()) {
        return emptyList();
    }
    String index = null;
    Integer shardId = null;
    String nodeId = null;
    if (randomBoolean()) {
        index = randomAsciiOfLength(5);
        shardId = randomInt();
        nodeId = usually() ? randomAsciiOfLength(5) : null;
    }
    return singletonList(new SearchFailure(new ElasticsearchException("foo"), index, shardId, nodeId));
}
Also used : SearchFailure(org.elasticsearch.action.bulk.byscroll.ScrollableHitSource.SearchFailure) TestUtil.randomSimpleString(org.apache.lucene.util.TestUtil.randomSimpleString) ElasticsearchException(org.elasticsearch.ElasticsearchException)

Example 5 with SearchFailure

use of org.elasticsearch.action.bulk.byscroll.ScrollableHitSource.SearchFailure in project elasticsearch by elastic.

the class BulkIndexByScrollResponseTests method testMergeConstructor.

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());
}
Also used : ArrayList(java.util.ArrayList) BulkItemResponse(org.elasticsearch.action.bulk.BulkItemResponse) BulkByScrollResponse(org.elasticsearch.action.bulk.byscroll.BulkByScrollResponse) SearchFailure(org.elasticsearch.action.bulk.byscroll.ScrollableHitSource.SearchFailure) BulkByScrollTask(org.elasticsearch.action.bulk.byscroll.BulkByScrollTask) SearchFailure(org.elasticsearch.action.bulk.byscroll.ScrollableHitSource.SearchFailure) TimeValue(org.elasticsearch.common.unit.TimeValue)

Aggregations

SearchFailure (org.elasticsearch.action.bulk.byscroll.ScrollableHitSource.SearchFailure)5 BulkItemResponse (org.elasticsearch.action.bulk.BulkItemResponse)2 Failure (org.elasticsearch.action.bulk.BulkItemResponse.Failure)2 ArrayList (java.util.ArrayList)1 TestUtil.randomSimpleString (org.apache.lucene.util.TestUtil.randomSimpleString)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 ActionResponse (org.elasticsearch.action.ActionResponse)1 DocWriteResponse (org.elasticsearch.action.DocWriteResponse)1 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)1 BulkByScrollResponse (org.elasticsearch.action.bulk.byscroll.BulkByScrollResponse)1 BulkByScrollTask (org.elasticsearch.action.bulk.byscroll.BulkByScrollTask)1 DeleteResponse (org.elasticsearch.action.delete.DeleteResponse)1 IndexResponse (org.elasticsearch.action.index.IndexResponse)1 ClearScrollResponse (org.elasticsearch.action.search.ClearScrollResponse)1 SearchResponse (org.elasticsearch.action.search.SearchResponse)1 ShardSearchFailure (org.elasticsearch.action.search.ShardSearchFailure)1 UpdateResponse (org.elasticsearch.action.update.UpdateResponse)1 TimeValue (org.elasticsearch.common.unit.TimeValue)1 InternalSearchResponse (org.elasticsearch.search.internal.InternalSearchResponse)1