protected void updateMetaSearchResults( SearchResponse searchResponse) { this.metaResults.addSuccessfulShards(searchResponse.getSuccessfulShards()); this.metaResults.addFailedShards(searchResponse.getFailedShards()); this.metaResults.addTotalNumOfShards(searchResponse.getTotalShards()); this.metaResults.updateTimeOut(searchResponse.isTimedOut()); }
@Test(expected = InvalidSearchException.class) public void searchShouldFailWhenNotOK() throws InvalidSearchException, IOException { // mocks SearchResponse response = mock(SearchResponse.class); SearchRequest request = new SearchRequest(); // response will have status of OK when(response.status()).thenReturn(RestStatus.PARTIAL_CONTENT); when(response.getFailedShards()).thenReturn(0); when(response.getTotalShards()).thenReturn(2); // search should succeed ElasticsearchRequestSubmitter submitter = setup(response); submitter.submitSearch(request); }
@Test public void searchShouldSucceedWhenOK() throws InvalidSearchException, IOException { // mocks SearchResponse response = mock(SearchResponse.class); SearchRequest request = new SearchRequest(); // response will indicate 1 search hit SearchHits hits = mock(SearchHits.class); when(hits.getTotalHits()).thenReturn(1L); // response will have status of OK and no failed shards when(response.status()).thenReturn(RestStatus.OK); when(response.getFailedShards()).thenReturn(0); when(response.getTotalShards()).thenReturn(2); when(response.getHits()).thenReturn(hits); // search should succeed ElasticsearchRequestSubmitter submitter = setup(response); SearchResponse actual = submitter.submitSearch(request); assertNotNull(actual); }
when(response.getTotalShards()).thenReturn(2); when(response.getHits()).thenReturn(hits);
LOG.error("Search resulted in {}/{} shards failing; errors={}, search={}", response.getFailedShards(), response.getTotalShards(), errors, ElasticsearchUtils.toJSON(request).orElse("???"));
@Override public int getTotalShards() { return searchResponse.getTotalShards(); }
@Override @Deprecated public int getTotalShards() { return super.getTotalShards(); }
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; }
public static void assertAllSuccessful(SearchResponse response) { assertNoFailures(response); assertThat("Expected all shards successful", response.getSuccessfulShards(), equalTo(response.getTotalShards())); assertVersionSerializable(response); }
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(); }
@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); } });
protected void updateMetaSearchResults( SearchResponse searchResponse) { this.metaResults.addSuccessfulShards(searchResponse.getSuccessfulShards()); this.metaResults.addFailedShards(searchResponse.getFailedShards()); this.metaResults.addTotalNumOfShards(searchResponse.getTotalShards()); this.metaResults.updateTimeOut(searchResponse.isTimedOut()); }
private void setBasicResponseInfo(SearchResponse searchResponse, JdbcSearchResponse<String> jdbcResponse) { jdbcResponse.setFailedShards(searchResponse.getFailedShards()); jdbcResponse.setSuccessfulShards(searchResponse.getSuccessfulShards()); jdbcResponse.setTookInMillis(searchResponse.getTookInMillis()); jdbcResponse.setTotalShards(searchResponse.getTotalShards()); }
@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; }