/** * Creates a new search response from the given merged hits. * @see #merge(boolean, ReducedQueryPhase, Collection, IntFunction) */ public InternalSearchResponse buildResponse(SearchHits hits) { return new InternalSearchResponse(hits, aggregations, suggest, shardResults, timedOut, terminatedEarly, numReducePhases); } }
/** * The search hits. */ public SearchHits getHits() { return internalResponse.hits(); }
/** * This is the main entry point for a search. This method starts the search execution of the initial phase. */ public final void start() { if (getNumShards() == 0) { //no search shards to search on, bail with empty response //(it happens with search across _all with no indices around and consistent with broadcast operations) listener.onResponse(new SearchResponse(InternalSearchResponse.empty(), null, 0, 0, 0, buildTookInMillis(), ShardSearchFailure.EMPTY_ARRAY, clusters)); return; } executePhase(this); }
public static InternalSearchResponse readInternalSearchResponse(StreamInput in) throws IOException { InternalSearchResponse response = new InternalSearchResponse(); response.readFrom(in); return response; }
return InternalSearchResponse.empty(); return new InternalSearchResponse(searchHits, aggregations, suggest, shardResults, timedOut, terminatedEarly);
/** * Has the search operation timed out. */ public boolean isTimedOut() { return internalResponse.timedOut(); }
@Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); internalResponse.writeTo(out); out.writeVInt(totalShards); out.writeVInt(successfulShards); out.writeVInt(shardFailures.length); for (ShardSearchFailure shardSearchFailure : shardFailures) { shardSearchFailure.writeTo(out); } out.writeOptionalString(scrollId); out.writeVLong(tookInMillis); }
@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, timedOut()); builder.startObject(Fields._SHARDS); builder.field(Fields.TOTAL, totalShards()); builder.field(Fields.SUCCESSFUL, successfulShards()); builder.field(Fields.FAILED, failedShards()); if (shardFailures.length > 0) { builder.startArray(Fields.FAILURES); for (ShardSearchFailure shardFailure : shardFailures) { builder.startObject(); if (shardFailure.shard() != null) { builder.field(Fields.INDEX, shardFailure.shard().index()); builder.field(Fields.SHARD, shardFailure.shard().shardId()); } builder.field(Fields.STATUS, shardFailure.status().getStatus()); builder.field(Fields.REASON, shardFailure.reason()); builder.endObject(); } builder.endArray(); } builder.endObject(); internalResponse.toXContent(builder, params); return builder; }
@Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); internalResponse = readInternalSearchResponse(in); totalShards = in.readVInt(); successfulShards = in.readVInt(); int size = in.readVInt(); if (size == 0) { shardFailures = ShardSearchFailure.EMPTY_ARRAY; } else { shardFailures = new ShardSearchFailure[size]; for (int i = 0; i < shardFailures.length; i++) { shardFailures[i] = readShardSearchFailure(in); } } scrollId = in.readOptionalString(); tookInMillis = in.readVLong(); }
/** * Has the search operation timed out. */ public boolean timedOut() { return internalResponse.timedOut(); }
@Override public void writeTo(StreamOutput out) throws IOException { internalResponse.writeTo(out); out.writeVInt(totalShards); out.writeVInt(successfulShards); out.writeVInt(shardFailures.length); for (ShardSearchFailure shardSearchFailure : shardFailures) { shardSearchFailure.writeTo(out); } if (scrollId == null) { out.writeBoolean(false); } else { out.writeBoolean(true); out.writeString(scrollId); } out.writeVLong(tookInMillis); }
@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; }
@Override public void readFrom(StreamInput in) throws IOException { internalResponse = readInternalSearchResponse(in); totalShards = in.readVInt(); successfulShards = in.readVInt(); int size = in.readVInt(); if (size == 0) { shardFailures = ShardSearchFailure.EMPTY_ARRAY; } else { shardFailures = new ShardSearchFailure[size]; for (int i = 0; i < shardFailures.length; i++) { shardFailures[i] = readShardSearchFailure(in); } } if (in.readBoolean()) { scrollId = in.readString(); } tookInMillis = in.readVLong(); }
public static InternalSearchResponse empty() { return new InternalSearchResponse(SearchHits.empty(), null, null, null, false, null, 1); }
/** * The search hits. */ public SearchHits hits() { return internalResponse.hits(); }
IntFunction<SearchPhaseResult> resultsLookup) { if (reducedQueryPhase.isEmptyResult) { return InternalSearchResponse.empty();
/** * Creates a new search response from the given merged hits. * @see #merge(boolean, ReducedQueryPhase, Collection, IntFunction) */ public InternalSearchResponse buildResponse(SearchHits hits) { return new InternalSearchResponse(hits, aggregations, suggest, shardResults, timedOut, terminatedEarly, numReducePhases); } }
@Override public void run() throws IOException { if (isCollapseRequest() && searchResponse.hits().getHits().length > 0) { SearchRequest searchRequest = context.getRequest(); CollapseBuilder collapseBuilder = searchRequest.source().collapse(); multiRequest.maxConcurrentSearchRequests(collapseBuilder.getMaxConcurrentGroupRequests()); for (SearchHit hit : searchResponse.hits().getHits()) { BoolQueryBuilder groupQuery = new BoolQueryBuilder(); Object collapseValue = hit.field(collapseBuilder.getField()).getValue();
/** * This is the main entry point for a search. This method starts the search execution of the initial phase. */ public final void start() { if (getNumShards() == 0) { //no search shards to search on, bail with empty response //(it happens with search across _all with no indices around and consistent with broadcast operations) listener.onResponse(new SearchResponse(InternalSearchResponse.empty(), null, 0, 0, buildTookInMillis(), ShardSearchFailure.EMPTY_ARRAY)); return; } executePhase(this); }
/** * Creates a new search response from the given merged hits. * @see #merge(boolean, ReducedQueryPhase, Collection, IntFunction) */ public InternalSearchResponse buildResponse(SearchHits hits) { return new InternalSearchResponse(hits, aggregations, suggest, shardResults, timedOut, terminatedEarly, numReducePhases); } }