|
@@ -15,6 +15,11 @@ import org.elasticsearch.action.index.IndexRequest;
|
|
|
import org.elasticsearch.action.search.SearchAction;
|
|
|
import org.elasticsearch.action.search.SearchRequest;
|
|
|
import org.elasticsearch.action.search.SearchResponse;
|
|
|
+import org.elasticsearch.action.search.SearchShardsAction;
|
|
|
+import org.elasticsearch.action.search.SearchShardsGroup;
|
|
|
+import org.elasticsearch.action.search.SearchShardsRequest;
|
|
|
+import org.elasticsearch.action.search.SearchShardsResponse;
|
|
|
+import org.elasticsearch.action.support.IndicesOptions;
|
|
|
import org.elasticsearch.action.support.PlainActionFuture;
|
|
|
import org.elasticsearch.action.support.WriteRequest;
|
|
|
import org.elasticsearch.client.internal.Client;
|
|
@@ -26,6 +31,7 @@ import org.elasticsearch.common.util.CollectionUtils;
|
|
|
import org.elasticsearch.core.TimeValue;
|
|
|
import org.elasticsearch.index.IndexModule;
|
|
|
import org.elasticsearch.index.query.MatchAllQueryBuilder;
|
|
|
+import org.elasticsearch.index.query.QueryBuilder;
|
|
|
import org.elasticsearch.index.query.TermQueryBuilder;
|
|
|
import org.elasticsearch.index.shard.SearchOperationListener;
|
|
|
import org.elasticsearch.plugins.Plugin;
|
|
@@ -60,6 +66,7 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcke
|
|
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
|
|
|
import static org.hamcrest.Matchers.contains;
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
+import static org.hamcrest.Matchers.hasSize;
|
|
|
import static org.hamcrest.Matchers.instanceOf;
|
|
|
import static org.hamcrest.Matchers.not;
|
|
|
import static org.hamcrest.Matchers.nullValue;
|
|
@@ -447,4 +454,64 @@ public class CrossClusterSearchIT extends AbstractMultiClustersTestCase {
|
|
|
super.onIndexModule(indexModule);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public void testSearchShardsWithIndexNameQuery() {
|
|
|
+ int numShards = randomIntBetween(1, 10);
|
|
|
+ Client remoteClient = client("cluster_a");
|
|
|
+ remoteClient.admin()
|
|
|
+ .indices()
|
|
|
+ .prepareCreate("my_index")
|
|
|
+ .setSettings(Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, numShards))
|
|
|
+ .get();
|
|
|
+ int numDocs = randomIntBetween(100, 500);
|
|
|
+ for (int i = 0; i < numDocs; i++) {
|
|
|
+ remoteClient.prepareIndex("my_index").setSource("f", "v").get();
|
|
|
+ }
|
|
|
+ remoteClient.admin().indices().prepareRefresh("my_index").get();
|
|
|
+ String[] indices = new String[] { "my_index" };
|
|
|
+ IndicesOptions indicesOptions = IndicesOptions.strictSingleIndexNoExpandForbidClosed();
|
|
|
+ {
|
|
|
+ QueryBuilder query = new TermQueryBuilder("_index", "cluster_a:my_index");
|
|
|
+ SearchShardsRequest request = new SearchShardsRequest(indices, indicesOptions, query, null, null, randomBoolean(), "cluster_a");
|
|
|
+ SearchShardsResponse resp = remoteClient.execute(SearchShardsAction.INSTANCE, request).actionGet();
|
|
|
+ assertThat(resp.getGroups(), hasSize(numShards));
|
|
|
+ for (SearchShardsGroup group : resp.getGroups()) {
|
|
|
+ assertFalse(group.skipped());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ {
|
|
|
+ QueryBuilder query = new TermQueryBuilder("_index", "cluster_a:my_index");
|
|
|
+ SearchShardsRequest request = new SearchShardsRequest(
|
|
|
+ indices,
|
|
|
+ indicesOptions,
|
|
|
+ query,
|
|
|
+ null,
|
|
|
+ null,
|
|
|
+ randomBoolean(),
|
|
|
+ randomFrom("cluster_b", null)
|
|
|
+ );
|
|
|
+ SearchShardsResponse resp = remoteClient.execute(SearchShardsAction.INSTANCE, request).actionGet();
|
|
|
+ assertThat(resp.getGroups(), hasSize(numShards));
|
|
|
+ for (SearchShardsGroup group : resp.getGroups()) {
|
|
|
+ assertTrue(group.skipped());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ {
|
|
|
+ QueryBuilder query = new TermQueryBuilder("_index", "cluster_a:not_my_index");
|
|
|
+ SearchShardsRequest request = new SearchShardsRequest(
|
|
|
+ indices,
|
|
|
+ indicesOptions,
|
|
|
+ query,
|
|
|
+ null,
|
|
|
+ null,
|
|
|
+ randomBoolean(),
|
|
|
+ randomFrom("cluster_a", "cluster_b", null)
|
|
|
+ );
|
|
|
+ SearchShardsResponse resp = remoteClient.execute(SearchShardsAction.INSTANCE, request).actionGet();
|
|
|
+ assertThat(resp.getGroups(), hasSize(numShards));
|
|
|
+ for (SearchShardsGroup group : resp.getGroups()) {
|
|
|
+ assertTrue(group.skipped());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|