Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove InternalSearchResponse as well as most usage of SearchResponseSections #103583

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.internal.InternalSearchResponse;
import org.elasticsearch.search.profile.SearchProfileResults;
import org.elasticsearch.search.suggest.Suggest;
import org.elasticsearch.tasks.Task;
Expand All @@ -45,15 +44,13 @@ public TransportNoopSearchAction(TransportService transportService, ActionFilter
protected void doExecute(Task task, SearchRequest request, ActionListener<SearchResponse> listener) {
listener.onResponse(
new SearchResponse(
new InternalSearchResponse(
new SearchHits(new SearchHit[0], new TotalHits(0L, TotalHits.Relation.EQUAL_TO), 0.0f),
InternalAggregations.EMPTY,
new Suggest(Collections.emptyList()),
new SearchProfileResults(Collections.emptyMap()),
false,
false,
1
),
new SearchHits(new SearchHit[0], new TotalHits(0L, TotalHits.Relation.EQUAL_TO), 0.0f),
InternalAggregations.EMPTY,
new Suggest(Collections.emptyList()),
false,
false,
new SearchProfileResults(Collections.emptyMap()),
1,
"",
1,
1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.elasticsearch.action.ActionFuture;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchResponseSections;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
Expand Down Expand Up @@ -321,16 +320,7 @@ private String mockSearches(String databaseName, int firstChunk, int lastChunk)
}

SearchHits hits = new SearchHits(new SearchHit[] { hit }, new TotalHits(1, TotalHits.Relation.EQUAL_TO), 1f);
SearchResponse searchResponse = new SearchResponse(
new SearchResponseSections(hits, null, null, false, null, null, 0),
null,
1,
1,
0,
1L,
null,
null
);
SearchResponse searchResponse = new SearchResponse(hits, null, null, false, null, null, 0, null, 1, 1, 0, 1L, null, null);
@SuppressWarnings("unchecked")
ActionFuture<SearchResponse> actionFuture = mock(ActionFuture.class);
when(actionFuture.actionGet()).thenReturn(searchResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.ShardSearchFailure;
import org.elasticsearch.common.Strings;
import org.elasticsearch.search.internal.InternalSearchResponse;
import org.elasticsearch.search.SearchResponseUtils;
import org.elasticsearch.test.AbstractXContentTestCase;
import org.elasticsearch.xcontent.ToXContent;
import org.elasticsearch.xcontent.XContentParser;
Expand All @@ -38,11 +38,9 @@ protected MultiSearchTemplateResponse createTestInstance() {
int totalShards = randomIntBetween(1, Integer.MAX_VALUE);
int successfulShards = randomIntBetween(0, totalShards);
int skippedShards = totalShards - successfulShards;
InternalSearchResponse internalSearchResponse = InternalSearchResponse.EMPTY_WITH_TOTAL_HITS;
SearchResponse.Clusters clusters = randomClusters();
SearchTemplateResponse searchTemplateResponse = new SearchTemplateResponse();
SearchResponse searchResponse = new SearchResponse(
internalSearchResponse,
SearchResponse searchResponse = SearchResponseUtils.emptyWithTotalHits(
null,
totalShards,
successfulShards,
Expand Down Expand Up @@ -75,11 +73,9 @@ private static MultiSearchTemplateResponse createTestInstanceWithFailures() {
int totalShards = randomIntBetween(1, Integer.MAX_VALUE);
int successfulShards = randomIntBetween(0, totalShards);
int skippedShards = totalShards - successfulShards;
InternalSearchResponse internalSearchResponse = InternalSearchResponse.EMPTY_WITH_TOTAL_HITS;
SearchResponse.Clusters clusters = randomClusters();
SearchTemplateResponse searchTemplateResponse = new SearchTemplateResponse();
SearchResponse searchResponse = new SearchResponse(
internalSearchResponse,
SearchResponse searchResponse = SearchResponseUtils.emptyWithTotalHits(
null,
totalShards,
successfulShards,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.internal.InternalSearchResponse;
import org.elasticsearch.search.SearchResponseUtils;
import org.elasticsearch.test.AbstractXContentTestCase;
import org.elasticsearch.xcontent.ToXContent;
import org.elasticsearch.xcontent.XContentBuilder;
Expand Down Expand Up @@ -54,10 +54,8 @@ private static SearchResponse createSearchResponse() {
int totalShards = randomIntBetween(1, Integer.MAX_VALUE);
int successfulShards = randomIntBetween(0, totalShards);
int skippedShards = randomIntBetween(0, totalShards);
InternalSearchResponse internalSearchResponse = InternalSearchResponse.EMPTY_WITH_TOTAL_HITS;

return new SearchResponse(
internalSearchResponse,
return SearchResponseUtils.emptyWithTotalHits(
null,
totalShards,
successfulShards,
Expand Down Expand Up @@ -161,17 +159,14 @@ public void testSearchResponseToXContent() throws IOException {
hit.score(2.0f);
SearchHit[] hits = new SearchHit[] { hit };

InternalSearchResponse internalSearchResponse = new InternalSearchResponse(
SearchResponse searchResponse = new SearchResponse(
new SearchHits(hits, new TotalHits(100, TotalHits.Relation.EQUAL_TO), 1.5f),
null,
null,
null,
false,
null,
1
);
SearchResponse searchResponse = new SearchResponse(
internalSearchResponse,
null,
1,
null,
0,
0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.internal.InternalSearchResponse;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.tasks.TaskId;
import org.elasticsearch.tasks.TaskManager;
Expand Down Expand Up @@ -574,9 +573,14 @@ protected RequestWrapper<?> buildRequest(Hit doc) {
new TotalHits(0, TotalHits.Relation.EQUAL_TO),
0
);
InternalSearchResponse internalResponse = new InternalSearchResponse(hits, null, null, null, false, false, 1);
SearchResponse searchResponse = new SearchResponse(
internalResponse,
hits,
null,
null,
false,
false,
null,
1,
scrollId(),
5,
4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.elasticsearch.index.reindex.ScrollableHitSource;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.internal.InternalSearchResponse;
import org.elasticsearch.tasks.TaskId;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.TestThreadPool;
Expand Down Expand Up @@ -169,9 +168,14 @@ private SearchResponse createSearchResponse() {
new TotalHits(0, TotalHits.Relation.EQUAL_TO),
0
);
InternalSearchResponse internalResponse = new InternalSearchResponse(hits, null, null, null, false, false, 1);
return new SearchResponse(
internalResponse,
hits,
null,
null,
false,
false,
null,
1,
randomSimpleString(random(), 1, 10),
5,
4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.elasticsearch.common.util.concurrent.EsExecutors;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.internal.InternalSearchResponse;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.ObjectPath;
import org.elasticsearch.test.transport.MockTransportService;
Expand Down Expand Up @@ -92,28 +91,24 @@ private static MockTransportService startTransport(
TransportSearchAction.TYPE.name(),
EsExecutors.DIRECT_EXECUTOR_SERVICE,
SearchRequest::new,
(request, channel, task) -> {
InternalSearchResponse response = new InternalSearchResponse(
(request, channel, task) -> channel.sendResponse(
new SearchResponse(
new SearchHits(new SearchHit[0], new TotalHits(0, TotalHits.Relation.EQUAL_TO), Float.NaN),
InternalAggregations.EMPTY,
null,
null,
false,
null,
1
);
SearchResponse searchResponse = new SearchResponse(
response,
null,
1,
null,
1,
1,
0,
100,
ShardSearchFailure.EMPTY_ARRAY,
SearchResponse.Clusters.EMPTY
);
channel.sendResponse(searchResponse);
}
)
)
);
newService.registerRequestHandler(
ClusterStateAction.NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
import org.elasticsearch.core.Releasables;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.search.SearchContextMissingException;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.SearchPhaseResult;
import org.elasticsearch.search.SearchShardTarget;
import org.elasticsearch.search.builder.PointInTimeBuilder;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.internal.AliasFilter;
import org.elasticsearch.search.internal.InternalSearchResponse;
import org.elasticsearch.search.internal.SearchContext;
import org.elasticsearch.search.internal.ShardSearchContextId;
import org.elasticsearch.search.internal.ShardSearchRequest;
Expand Down Expand Up @@ -212,7 +212,9 @@ public final void start() {
// total hits is null in the response if the tracking of total hits is disabled
boolean withTotalHits = trackTotalHitsUpTo != SearchContext.TRACK_TOTAL_HITS_DISABLED;
sendSearchResponse(
withTotalHits ? InternalSearchResponse.EMPTY_WITH_TOTAL_HITS : InternalSearchResponse.EMPTY_WITHOUT_TOTAL_HITS,
withTotalHits
? new SearchResponseSections(SearchHits.EMPTY_WITH_TOTAL_HITS, null, null, false, null, null, 1)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I inlined these, we don't really want constants for stuff that becomes ref-counted. We can make this nicer later one at some point IMO.

: new SearchResponseSections(SearchHits.EMPTY_WITHOUT_TOTAL_HITS, null, null, false, null, null, 1),
new AtomicArray<>(0)
);
return;
Expand Down Expand Up @@ -655,7 +657,7 @@ public boolean isPartOfPointInTime(ShardSearchContextId contextId) {
}

private SearchResponse buildSearchResponse(
InternalSearchResponse internalSearchResponse,
SearchResponseSections internalSearchResponse,
ShardSearchFailure[] failures,
String scrollId,
String searchContextId
Expand All @@ -682,7 +684,7 @@ boolean buildPointInTimeFromSearchResults() {
}

@Override
public void sendSearchResponse(InternalSearchResponse internalSearchResponse, AtomicArray<SearchPhaseResult> queryResults) {
public void sendSearchResponse(SearchResponseSections internalSearchResponse, AtomicArray<SearchPhaseResult> queryResults) {
ShardSearchFailure[] failures = buildShardFailures();
Boolean allowPartialResults = request.allowPartialSearchResults();
assert allowPartialResults != null : "SearchRequest missing setting for allowPartialSearchResults";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.collapse.CollapseBuilder;
import org.elasticsearch.search.internal.InternalSearchResponse;

import java.util.Iterator;
import java.util.List;
Expand All @@ -31,13 +30,13 @@
*/
final class ExpandSearchPhase extends SearchPhase {
private final SearchPhaseContext context;
private final InternalSearchResponse searchResponse;
private final SearchHits searchHits;
private final Supplier<SearchPhase> nextPhase;

ExpandSearchPhase(SearchPhaseContext context, InternalSearchResponse searchResponse, Supplier<SearchPhase> nextPhase) {
ExpandSearchPhase(SearchPhaseContext context, SearchHits searchHits, Supplier<SearchPhase> nextPhase) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only use the hits, so lets only pass around the hits => only have to worry about ref-counting the hits :)

super("expand");
this.context = context;
this.searchResponse = searchResponse;
this.searchHits = searchHits;
this.nextPhase = nextPhase;
}

Expand All @@ -53,15 +52,15 @@ private boolean isCollapseRequest() {

@Override
public void run() {
if (isCollapseRequest() && searchResponse.hits().getHits().length > 0) {
if (isCollapseRequest() && searchHits.getHits().length > 0) {
SearchRequest searchRequest = context.getRequest();
CollapseBuilder collapseBuilder = searchRequest.source().collapse();
final List<InnerHitBuilder> innerHitBuilders = collapseBuilder.getInnerHits();
MultiSearchRequest multiRequest = new MultiSearchRequest();
if (collapseBuilder.getMaxConcurrentGroupRequests() > 0) {
multiRequest.maxConcurrentSearchRequests(collapseBuilder.getMaxConcurrentGroupRequests());
}
for (SearchHit hit : searchResponse.hits().getHits()) {
for (SearchHit hit : searchHits.getHits()) {
BoolQueryBuilder groupQuery = new BoolQueryBuilder();
Object collapseValue = hit.field(collapseBuilder.getField()).getValue();
if (collapseValue != null) {
Expand All @@ -85,7 +84,7 @@ public void run() {
}
context.getSearchTransport().sendExecuteMultiSearch(multiRequest, context.getTask(), ActionListener.wrap(response -> {
Iterator<MultiSearchResponse.Item> it = response.iterator();
for (SearchHit hit : searchResponse.hits.getHits()) {
for (SearchHit hit : searchHits.getHits()) {
for (InnerHitBuilder innerHitBuilder : innerHitBuilders) {
MultiSearchResponse.Item item = it.next();
if (item.isFailure()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
import org.elasticsearch.common.util.Maps;
import org.elasticsearch.common.util.concurrent.AtomicArray;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.SearchPhaseResult;
import org.elasticsearch.search.fetch.subphase.LookupField;
import org.elasticsearch.search.internal.InternalSearchResponse;
import org.elasticsearch.transport.RemoteClusterService;

import java.util.ArrayList;
Expand All @@ -33,10 +33,10 @@
*/
final class FetchLookupFieldsPhase extends SearchPhase {
private final SearchPhaseContext context;
private final InternalSearchResponse searchResponse;
private final SearchResponseSections searchResponse;
private final AtomicArray<SearchPhaseResult> queryResults;

FetchLookupFieldsPhase(SearchPhaseContext context, InternalSearchResponse searchResponse, AtomicArray<SearchPhaseResult> queryResults) {
FetchLookupFieldsPhase(SearchPhaseContext context, SearchResponseSections searchResponse, AtomicArray<SearchPhaseResult> queryResults) {
super("fetch_lookup_fields");
this.context = context;
this.searchResponse = searchResponse;
Expand All @@ -47,9 +47,9 @@ private record Cluster(String clusterAlias, List<SearchHit> hitsWithLookupFields

}

private static List<Cluster> groupLookupFieldsByClusterAlias(InternalSearchResponse response) {
private static List<Cluster> groupLookupFieldsByClusterAlias(SearchHits searchHits) {
final Map<String, List<SearchHit>> perClusters = new HashMap<>();
for (SearchHit hit : response.hits.getHits()) {
for (SearchHit hit : searchHits.getHits()) {
String clusterAlias = hit.getClusterAlias() != null ? hit.getClusterAlias() : RemoteClusterService.LOCAL_CLUSTER_GROUP_KEY;
if (hit.hasLookupFields()) {
perClusters.computeIfAbsent(clusterAlias, k -> new ArrayList<>()).add(hit);
Expand All @@ -70,7 +70,7 @@ private static List<Cluster> groupLookupFieldsByClusterAlias(InternalSearchRespo

@Override
public void run() {
final List<Cluster> clusters = groupLookupFieldsByClusterAlias(searchResponse);
final List<Cluster> clusters = groupLookupFieldsByClusterAlias(searchResponse.hits);
if (clusters.isEmpty()) {
context.sendSearchResponse(searchResponse, queryResults);
return;
Expand Down
Loading