Skip to content

Commit

Permalink
Remove explicit SearchResponse references from `org.elasticsearch.sea…
Browse files Browse the repository at this point in the history
…rch.ccs` (#102076)
  • Loading branch information
iverase committed Nov 13, 2023
1 parent 44ca06a commit 3b07c40
Show file tree
Hide file tree
Showing 4 changed files with 353 additions and 327 deletions.
Expand Up @@ -13,7 +13,6 @@
import org.apache.lucene.index.PointValues;
import org.elasticsearch.action.search.CanMatchNodeRequest;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchTransportService;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.cluster.metadata.IndexMetadata;
Expand All @@ -34,7 +33,6 @@
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.test.AbstractMultiClustersTestCase;
import org.elasticsearch.test.hamcrest.ElasticsearchAssertions;
import org.elasticsearch.test.transport.MockTransportService;
import org.elasticsearch.transport.TransportService;
import org.hamcrest.Matchers;
Expand All @@ -46,6 +44,9 @@
import java.util.List;
import java.util.Optional;

import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertResponse;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.in;

Expand Down Expand Up @@ -103,7 +104,7 @@ protected Collection<Class<? extends Plugin>> nodePlugins(String clusterAlias) {
int createIndexAndIndexDocs(String cluster, String index, int numberOfShards, long timestamp, boolean exposeTimestamp)
throws Exception {
Client client = client(cluster);
ElasticsearchAssertions.assertAcked(
assertAcked(
client.admin()
.indices()
.prepareCreate(index)
Expand Down Expand Up @@ -175,11 +176,12 @@ public void testCanMatchOnTimeRange() throws Exception {
SearchSourceBuilder source = new SearchSourceBuilder().query(new RangeQueryBuilder("@timestamp").from(timestamp));
SearchRequest request = new SearchRequest("local_*", "*:remote_*");
request.source(source).setCcsMinimizeRoundtrips(minimizeRoundTrips);
SearchResponse searchResp = client().search(request).actionGet();
ElasticsearchAssertions.assertHitCount(searchResp, localDocs + remoteDocs);
int totalShards = oldLocalNumShards + newLocalNumShards + oldRemoteNumShards + newRemoteNumShards;
assertThat(searchResp.getTotalShards(), equalTo(totalShards));
assertThat(searchResp.getSkippedShards(), equalTo(oldLocalNumShards + oldRemoteNumShards));
assertResponse(client().search(request), response -> {
assertHitCount(response, localDocs + remoteDocs);
int totalShards = oldLocalNumShards + newLocalNumShards + oldRemoteNumShards + newRemoteNumShards;
assertThat(response.getTotalShards(), equalTo(totalShards));
assertThat(response.getSkippedShards(), equalTo(oldLocalNumShards + oldRemoteNumShards));
});
}
} finally {
for (String cluster : List.of(LOCAL_CLUSTER, REMOTE_CLUSTER)) {
Expand Down
Expand Up @@ -67,6 +67,7 @@

import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertResponse;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
Expand Down Expand Up @@ -130,13 +131,14 @@ public void testRemoteClusterClientRole() throws Exception {
.toList()
);

final SearchResponse resp = localCluster.client(nodeWithRemoteClusterClientRole)
.prepareSearch("demo", "cluster_a:prod")
.setQuery(new MatchAllQueryBuilder())
.setAllowPartialSearchResults(false)
.setSize(1000)
.get();
assertHitCount(resp, demoDocs + prodDocs);
assertHitCount(
localCluster.client(nodeWithRemoteClusterClientRole)
.prepareSearch("demo", "cluster_a:prod")
.setQuery(new MatchAllQueryBuilder())
.setAllowPartialSearchResults(false)
.setSize(1000),
demoDocs + prodDocs
);
}

public void testProxyConnectionDisconnect() throws Exception {
Expand Down Expand Up @@ -398,17 +400,21 @@ public void testLookupFields() throws Exception {
.fetchField("to");
SearchRequest request = new SearchRequest("cluster_a:remote_calls").source(searchSourceBuilder);
request.setCcsMinimizeRoundtrips(randomBoolean());
SearchResponse searchResponse = client().search(request).actionGet();
ElasticsearchAssertions.assertHitCount(searchResponse, 2);
SearchHit hit0 = searchResponse.getHits().getHits()[0];
assertThat(hit0.getIndex(), equalTo("remote_calls"));
assertThat(hit0.field("from"), nullValue());
assertThat(hit0.field("to").getValues(), contains(Map.of("name", List.of("Remote C"))));

SearchHit hit1 = searchResponse.getHits().getHits()[1];
assertThat(hit1.getIndex(), equalTo("remote_calls"));
assertThat(hit1.field("from").getValues(), contains(Map.of("name", List.of("Remote A")), Map.of("name", List.of("Remote B"))));
assertThat(hit1.field("to").getValues(), contains(Map.of("name", List.of("Remote C"))));
assertResponse(client().search(request), response -> {
ElasticsearchAssertions.assertHitCount(response, 2);
SearchHit hit0 = response.getHits().getHits()[0];
assertThat(hit0.getIndex(), equalTo("remote_calls"));
assertThat(hit0.field("from"), nullValue());
assertThat(hit0.field("to").getValues(), contains(Map.of("name", List.of("Remote C"))));

SearchHit hit1 = response.getHits().getHits()[1];
assertThat(hit1.getIndex(), equalTo("remote_calls"));
assertThat(
hit1.field("from").getValues(),
contains(Map.of("name", List.of("Remote A")), Map.of("name", List.of("Remote B")))
);
assertThat(hit1.field("to").getValues(), contains(Map.of("name", List.of("Remote C"))));
});
}
// Search on both clusters
{
Expand All @@ -419,22 +425,26 @@ public void testLookupFields() throws Exception {
.fetchField("to");
SearchRequest request = new SearchRequest("local_calls", "cluster_a:remote_calls").source(searchSourceBuilder);
request.setCcsMinimizeRoundtrips(randomBoolean());
SearchResponse searchResponse = client().search(request).actionGet();
ElasticsearchAssertions.assertHitCount(searchResponse, 3);
SearchHit hit0 = searchResponse.getHits().getHits()[0];
assertThat(hit0.getIndex(), equalTo("remote_calls"));
assertThat(hit0.field("from"), nullValue());
assertThat(hit0.field("to").getValues(), contains(Map.of("name", List.of("Remote C"))));

SearchHit hit1 = searchResponse.getHits().getHits()[1];
assertThat(hit1.getIndex(), equalTo("remote_calls"));
assertThat(hit1.field("from").getValues(), contains(Map.of("name", List.of("Remote A")), Map.of("name", List.of("Remote B"))));
assertThat(hit1.field("to").getValues(), contains(Map.of("name", List.of("Remote C"))));

SearchHit hit2 = searchResponse.getHits().getHits()[2];
assertThat(hit2.getIndex(), equalTo("local_calls"));
assertThat(hit2.field("from").getValues(), contains(Map.of("name", List.of("Local A"))));
assertThat(hit2.field("to").getValues(), contains(Map.of("name", List.of("Local B")), Map.of("name", List.of("Local C"))));
assertResponse(client().search(request), response -> {
assertHitCount(response, 3);
SearchHit hit0 = response.getHits().getHits()[0];
assertThat(hit0.getIndex(), equalTo("remote_calls"));
assertThat(hit0.field("from"), nullValue());
assertThat(hit0.field("to").getValues(), contains(Map.of("name", List.of("Remote C"))));

SearchHit hit1 = response.getHits().getHits()[1];
assertThat(hit1.getIndex(), equalTo("remote_calls"));
assertThat(
hit1.field("from").getValues(),
contains(Map.of("name", List.of("Remote A")), Map.of("name", List.of("Remote B")))
);
assertThat(hit1.field("to").getValues(), contains(Map.of("name", List.of("Remote C"))));

SearchHit hit2 = response.getHits().getHits()[2];
assertThat(hit2.getIndex(), equalTo("local_calls"));
assertThat(hit2.field("from").getValues(), contains(Map.of("name", List.of("Local A"))));
assertThat(hit2.field("to").getValues(), contains(Map.of("name", List.of("Local B")), Map.of("name", List.of("Local C"))));
});
}
}

Expand Down

0 comments on commit 3b07c40

Please sign in to comment.