private Response wrap(SearchResponse response) { List<SearchFailure> failures; if (response.getShardFailures() == null) { failures = emptyList(); } else { failures = new ArrayList<>(response.getShardFailures().length); for (ShardSearchFailure failure: response.getShardFailures()) { String nodeId = failure.shard() == null ? null : failure.shard().getNodeId(); failures.add(new SearchFailure(failure.getCause(), failure.index(), failure.shardId(), nodeId)); } } List<Hit> hits; if (response.getHits().getHits() == null || response.getHits().getHits().length == 0) { hits = emptyList(); } else { hits = new ArrayList<>(response.getHits().getHits().length); for (SearchHit hit: response.getHits().getHits()) { hits.add(new ClientHit(hit)); } hits = unmodifiableList(hits); } return new Response(response.isTimedOut(), failures, response.getHits().getTotalHits(), hits, response.getScrollId()); }
int errors = ArrayUtils.getLength(response.getShardFailures()); LOG.error("Search resulted in {}/{} shards failing; errors={}, search={}", response.getFailedShards(), for(ShardSearchFailure fail: response.getShardFailures()) { String msg = String.format( "Shard search failure [%s/%s]; reason=%s, index=%s, shard=%s, status=%s, nodeId=%s",
when(response.getShardFailures()).thenReturn(failures);
@Override public ShardSearchFailure[] getShardFailures() { return searchResponse.getShardFailures(); }
@Override @Deprecated public ShardSearchFailure[] getShardFailures() { return super.getShardFailures(); }
public static void assertNoFailures(SearchResponse searchResponse) { assertThat("Unexpected ShardFailures: " + Arrays.toString(searchResponse.getShardFailures()), searchResponse.getShardFailures().length, equalTo(0)); assertVersionSerializable(searchResponse); }
public static void assertFailures(SearchResponse searchResponse) { assertThat("Expected at least one shard failure, got none", searchResponse.getShardFailures().length, greaterThan(0)); assertVersionSerializable(searchResponse); }
public static String formatShardStatus(SearchResponse response) { StringBuilder msg = new StringBuilder(); msg.append(" Total shards: ").append(response.getTotalShards()) .append(" Successful shards: ").append(response.getSuccessfulShards()) .append(" & ").append(response.getFailedShards()).append(" shard failures:"); for (ShardSearchFailure failure : response.getShardFailures()) { msg.append("\n ").append(failure); } return msg.toString(); }
public XContentBuilder innerToXContent(XContentBuilder builder, Params params) throws IOException { if (scrollId != null) { builder.field(SCROLL_ID.getPreferredName(), scrollId); } builder.field(TOOK.getPreferredName(), tookInMillis); builder.field(TIMED_OUT.getPreferredName(), isTimedOut()); if (isTerminatedEarly() != null) { builder.field(TERMINATED_EARLY.getPreferredName(), isTerminatedEarly()); } if (getNumReducePhases() != 1) { builder.field(NUM_REDUCE_PHASES.getPreferredName(), getNumReducePhases()); } RestActions.buildBroadcastShardsHeader(builder, params, getTotalShards(), getSuccessfulShards(), getSkippedShards(), getFailedShards(), getShardFailures()); clusters.toXContent(builder, params); internalResponse.toXContent(builder, params); return builder; }
protected void validateRespose(final SearchResponse response) { final int totalShards = response.getTotalShards(); final int successfulShards = response.getSuccessfulShards(); if (totalShards != successfulShards) { throw new MissingShardsException(totalShards - successfulShards + " shards are failed."); } final ShardSearchFailure[] failures = response.getShardFailures(); if (failures.length > 0) { final StringBuilder buf = new StringBuilder(); for (final ShardOperationFailedException failure : failures) { buf.append('\n').append(failure.toString()); } throw new OperationFailedException("Search Operation Failed: " + buf.toString()); } }
public CountResponse(SearchResponse searchResponse) { super(searchResponse.getTotalShards(), searchResponse.getSuccessfulShards(), searchResponse.getFailedShards(), Arrays.asList(searchResponse.getShardFailures())); this.count = searchResponse.getHits().totalHits(); this.terminatedEarly = searchResponse.isTerminatedEarly() != null && searchResponse.isTerminatedEarly(); }
public static SearchResponse checkForFailures(SearchResponse searchResponse) { ShardSearchFailure[] shardFailures = searchResponse.getShardFailures(); if (shardFailures.length > 0) { for (ShardSearchFailure shardFailure : shardFailures) { LOGGER.error("search response shard failure", shardFailure.getCause()); } throw new VertexiumException("search response shard failures", shardFailures[0].getCause()); } return searchResponse; } }
public static SearchResponse checkForFailures(SearchResponse searchResponse) { ShardSearchFailure[] shardFailures = searchResponse.getShardFailures(); if (shardFailures.length > 0) { for (ShardSearchFailure shardFailure : shardFailures) { LOGGER.error("search response shard failure", shardFailure.getCause()); } throw new VertexiumException("search response shard failures", shardFailures[0].getCause()); } return searchResponse; } }
@Override public RestResponse buildResponse(SearchResponse response, XContentBuilder builder) throws Exception { builder.startObject(); if (terminateAfter != DEFAULT_TERMINATE_AFTER) { builder.field("terminated_early", response.isTerminatedEarly()); } builder.field("count", response.getHits().totalHits()); buildBroadcastShardsHeader(builder, request, response.getTotalShards(), response.getSuccessfulShards(), response.getFailedShards(), response.getShardFailures()); builder.endObject(); return new BytesRestResponse(response.status(), builder); } });
public static void assertFailures(SearchRequestBuilder searchRequestBuilder, RestStatus restStatus, Matcher<String> reasonMatcher) { //when the number for shards is randomized and we expect failures //we can either run into partial or total failures depending on the current number of shards try { SearchResponse searchResponse = searchRequestBuilder.get(); assertThat("Expected shard failures, got none", searchResponse.getShardFailures().length, greaterThan(0)); for (ShardSearchFailure shardSearchFailure : searchResponse.getShardFailures()) { assertThat(shardSearchFailure.status(), equalTo(restStatus)); assertThat(shardSearchFailure.reason(), reasonMatcher); } assertVersionSerializable(searchResponse); } catch (ElasticsearchException e) { assertThat(e.status(), equalTo(restStatus)); assertThat(e.toString(), reasonMatcher); } catch (Exception e) { fail("ElasticsearchException expected but got " + e.getClass()); } }
public long runQuery(String name, int testNum, String index, long expectedHits, QueryBuilder query) { SearchResponse searchResponse = new CoordinateSearchRequestBuilder(client) .setIndices(index) .setQuery(query) .execute().actionGet(); if (searchResponse.getFailedShards() > 0) { log("Search Failures " + Arrays.toString(searchResponse.getShardFailures())); } long hits = searchResponse.getHits().totalHits(); if (hits != expectedHits) { log("[" + name + "][#" + testNum + "] Hits Mismatch: expected [" + expectedHits + "], got [" + hits + "]"); } return searchResponse.getTookInMillis(); }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { if (scrollId != null) { builder.field(Fields._SCROLL_ID, scrollId); } builder.field(Fields.TOOK, tookInMillis); builder.field(Fields.TIMED_OUT, isTimedOut()); if (isTerminatedEarly() != null) { builder.field(Fields.TERMINATED_EARLY, isTerminatedEarly()); } RestActions.buildBroadcastShardsHeader(builder, params, getTotalShards(), getSuccessfulShards(), getFailedShards(), getShardFailures()); internalResponse.toXContent(builder, params); return builder; }
public XContentBuilder innerToXContent(XContentBuilder builder, Params params) throws IOException { if (scrollId != null) { builder.field(SCROLL_ID.getPreferredName(), scrollId); } builder.field(TOOK.getPreferredName(), tookInMillis); builder.field(TIMED_OUT.getPreferredName(), isTimedOut()); if (isTerminatedEarly() != null) { builder.field(TERMINATED_EARLY.getPreferredName(), isTerminatedEarly()); } if (getNumReducePhases() != 1) { builder.field(NUM_REDUCE_PHASES.getPreferredName(), getNumReducePhases()); } RestActions.buildBroadcastShardsHeader(builder, params, getTotalShards(), getSuccessfulShards(), getFailedShards(), getShardFailures()); internalResponse.toXContent(builder, params); return builder; }
public XContentBuilder innerToXContent(XContentBuilder builder, Params params) throws IOException { if (scrollId != null) { builder.field(SCROLL_ID.getPreferredName(), scrollId); } builder.field(TOOK.getPreferredName(), tookInMillis); builder.field(TIMED_OUT.getPreferredName(), isTimedOut()); if (isTerminatedEarly() != null) { builder.field(TERMINATED_EARLY.getPreferredName(), isTerminatedEarly()); } if (getNumReducePhases() != 1) { builder.field(NUM_REDUCE_PHASES.getPreferredName(), getNumReducePhases()); } RestActions.buildBroadcastShardsHeader(builder, params, getTotalShards(), getSuccessfulShards(), getSkippedShards(), getFailedShards(), getShardFailures()); clusters.toXContent(builder, params); internalResponse.toXContent(builder, params); return builder; }
public XContentBuilder innerToXContent(XContentBuilder builder, Params params) throws IOException { if (scrollId != null) { builder.field(SCROLL_ID.getPreferredName(), scrollId); } builder.field(TOOK.getPreferredName(), tookInMillis); builder.field(TIMED_OUT.getPreferredName(), isTimedOut()); if (isTerminatedEarly() != null) { builder.field(TERMINATED_EARLY.getPreferredName(), isTerminatedEarly()); } if (getNumReducePhases() != 1) { builder.field(NUM_REDUCE_PHASES.getPreferredName(), getNumReducePhases()); } RestActions.buildBroadcastShardsHeader(builder, params, getTotalShards(), getSuccessfulShards(), getSkippedShards(), getFailedShards(), getShardFailures()); clusters.toXContent(builder, params); internalResponse.toXContent(builder, params); return builder; }