@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { Throwable ex = ExceptionsHelper.unwrapCause(this); if (ex != this) { generateThrowableXContent(builder, params, this); } else { // We don't have a cause when all shards failed, but we do have shards failures so we can "guess" a cause // (see {@link #getCause()}). Here, we use super.getCause() because we don't want the guessed exception to // be rendered twice (one in the "cause" field, one in "failed_shards") innerToXContent(builder, params, this, getExceptionName(), getMessage(), getHeaders(), getMetadata(), super.getCause()); } return builder; }
@Override public final void onPhaseFailure(SearchPhase phase, String msg, Throwable cause) { raisePhaseFailure(new SearchPhaseExecutionException(phase.getName(), msg, cause, buildShardFailures())); }
@Override public String toString() { return buildMessage(phaseName, getMessage(), shardFailures); }
@Override public long count(TypeDescriptor typeDescriptor, Object query) throws ClientException { checkClient(); // TODO check for fetch none JsonNode queryMap = queryConverter.convertQuery(query); SearchRequestBuilder searchReqBuilder = esClientProvider.getClient().prepareSearch(typeDescriptor.getIndex()); SearchHits searchHits = null; try { SearchResponse response = searchReqBuilder.setTypes(typeDescriptor.getType()) .setSource(toSearchSourceBuilder(queryMap)) .execute() .actionGet(getQueryTimeout()); searchHits = response.getHits(); } catch (IndexNotFoundException infe) { logger.warn("Cannot find index '{}'", typeDescriptor.getIndex()); } catch (SearchPhaseExecutionException spee) { logger.warn("Generic search error {}", spee.getMessage(), spee); } if (searchHits == null) { return 0; } return searchHits.getTotalHits(); }
@Override public Throwable getCause() { Throwable cause = super.getCause(); if (cause == null) { // fall back to guessed root cause for (ElasticsearchException rootCause : guessRootCauses()) { return rootCause; } } return cause; }
public SearchPhaseExecutionException(String phaseName, String msg, Throwable cause, ShardSearchFailure[] shardFailures) { super(msg, deduplicateCause(cause, shardFailures)); this.phaseName = phaseName; this.shardFailures = shardFailures; }
@Override public long count(TypeDescriptor typeDescriptor, Object query) throws ClientException { checkClient(); // TODO check for fetch none JsonNode queryMap = queryConverter.convertQuery(query); SearchRequestBuilder searchReqBuilder = esClientProvider.getClient().prepareSearch(typeDescriptor.getIndex()); SearchHits searchHits = null; try { SearchResponse response = searchReqBuilder.setTypes(typeDescriptor.getType()) .setSource(toSearchSourceBuilder(queryMap)) .execute() .actionGet(getQueryTimeout()); searchHits = response.getHits(); } catch (IndexNotFoundException infe) { logger.warn("Cannot find index '{}'", typeDescriptor.getIndex()); } catch (SearchPhaseExecutionException spee) { logger.warn("Generic search error {}", spee.getMessage(), spee); } if (searchHits == null) { return 0; } return searchHits.getTotalHits(); }
@Override public Throwable getCause() { Throwable cause = super.getCause(); if (cause == null) { // fall back to guessed root cause for (ElasticsearchException rootCause : guessRootCauses()) { return rootCause; } } return cause; }
public SearchPhaseExecutionException(String phaseName, String msg, Throwable cause, ShardSearchFailure[] shardFailures) { super(msg, deduplicateCause(cause, shardFailures)); this.phaseName = phaseName; this.shardFailures = shardFailures; }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { Throwable ex = ExceptionsHelper.unwrapCause(this); if (ex != this) { generateThrowableXContent(builder, params, this); } else { // We don't have a cause when all shards failed, but we do have shards failures so we can "guess" a cause // (see {@link #getCause()}). Here, we use super.getCause() because we don't want the guessed exception to // be rendered twice (one in the "cause" field, one in "failed_shards") innerToXContent(builder, params, this, getExceptionName(), getMessage(), getHeaders(), getMetadata(), super.getCause()); } return builder; }
@Override public final SearchResponse buildSearchResponse(InternalSearchResponse internalSearchResponse, String scrollId) { ShardSearchFailure[] failures = buildShardFailures(); Boolean allowPartialResults = request.allowPartialSearchResults(); assert allowPartialResults != null : "SearchRequest missing setting for allowPartialSearchResults"; if (allowPartialResults == false && failures.length > 0){ raisePhaseFailure(new SearchPhaseExecutionException("", "Shard failures", null, failures)); } return new SearchResponse(internalSearchResponse, scrollId, getNumShards(), successfulOps.get(), skippedOps.get(), buildTookInMillis(), failures, clusters); }
@Override public String toString() { return buildMessage(phaseName, getMessage(), shardFailures); }
logger.warn("Cannot find index '{}'", typeDescriptor.getIndex()); } catch (SearchPhaseExecutionException spee) { logger.warn("Generic search error {}", spee.getMessage(), spee);
@Override public Throwable getCause() { Throwable cause = super.getCause(); if (cause == null) { // fall back to guessed root cause for (ElasticsearchException rootCause : guessRootCauses()) { return rootCause; } } return cause; }
public SearchPhaseExecutionException(String phaseName, String msg, Throwable cause, ShardSearchFailure[] shardFailures) { super(msg, deduplicateCause(cause, shardFailures)); this.phaseName = phaseName; this.shardFailures = shardFailures; }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { Throwable ex = ExceptionsHelper.unwrapCause(this); if (ex != this) { generateThrowableXContent(builder, params, this); } else { // We don't have a cause when all shards failed, but we do have shards failures so we can "guess" a cause // (see {@link #getCause()}). Here, we use super.getCause() because we don't want the guessed exception to // be rendered twice (one in the "cause" field, one in "failed_shards") innerToXContent(builder, params, this, getExceptionName(), getMessage(), getHeaders(), getMetadata(), super.getCause()); } return builder; }
protected void onShardFailure(String phaseName, final CountDown counter, final long searchId, Exception failure, @Nullable SearchShardTarget searchShardTarget, Supplier<SearchPhase> nextPhaseSupplier) { if (logger.isDebugEnabled()) { logger.debug(new ParameterizedMessage("[{}] Failed to execute {} phase", searchId, phaseName), failure); } addShardFailure(new ShardSearchFailure(failure, searchShardTarget)); int successfulOperations = successfulOps.decrementAndGet(); assert successfulOperations >= 0 : "successfulOperations must be >= 0 but was: " + successfulOperations; if (counter.countDown()) { if (successfulOps.get() == 0) { listener.onFailure(new SearchPhaseExecutionException(phaseName, "all shards failed", failure, buildShardFailures())); } else { SearchPhase phase = nextPhaseSupplier.get(); try { phase.run(); } catch (Exception e) { e.addSuppressed(failure); listener.onFailure(new SearchPhaseExecutionException(phase.getName(), "Phase failed", e, ShardSearchFailure.EMPTY_ARRAY)); } } } }
@Override public String toString() { return buildMessage(phaseName, getMessage(), shardFailures); }
logger.warn("Cannot find index '{}'", typeDescriptor.getIndex()); } catch (SearchPhaseExecutionException spee) { logger.warn("Generic search error {}", spee.getMessage(), spee);
@Override public Throwable getCause() { Throwable cause = super.getCause(); if (cause == null) { // fall back to guessed root cause for (ElasticsearchException rootCause : guessRootCauses()) { return rootCause; } } return cause; }