-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cross cluster support to _terms_enum (#73478)
This commit adds the support to search cross cluster indices (with the cross cluster syntax) in the _terms_enum API. Relates #71550
- Loading branch information
Showing
11 changed files
with
633 additions
and
159 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
...e/src/internalClusterTest/java/org/elasticsearch/xpack/core/termsenum/CCSTermsEnumIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
package org.elasticsearch.xpack.core.termsenum; | ||
|
||
import org.elasticsearch.client.Client; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.plugins.Plugin; | ||
import org.elasticsearch.test.AbstractMultiClustersTestCase; | ||
import org.elasticsearch.xpack.core.LocalStateCompositeXPackPlugin; | ||
import org.elasticsearch.xpack.core.termsenum.action.TermsEnumAction; | ||
import org.elasticsearch.xpack.core.termsenum.action.TermsEnumRequest; | ||
import org.elasticsearch.xpack.core.termsenum.action.TermsEnumResponse; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
public class CCSTermsEnumIT extends AbstractMultiClustersTestCase { | ||
|
||
@Override | ||
protected Collection<String> remoteClusterAlias() { | ||
return List.of("remote_cluster"); | ||
} | ||
|
||
@Override | ||
protected Collection<Class<? extends Plugin>> nodePlugins(String clusterAlias) { | ||
final List<Class<? extends Plugin>> plugins = new ArrayList<>(super.nodePlugins(clusterAlias)); | ||
plugins.add(LocalStateCompositeXPackPlugin.class); | ||
return plugins; | ||
} | ||
|
||
public void testBasic() { | ||
Settings indexSettings = Settings.builder().put("index.number_of_replicas", 0).build(); | ||
final Client localClient = client(LOCAL_CLUSTER); | ||
final Client remoteClient = client("remote_cluster"); | ||
String localIndex = "local_test"; | ||
assertAcked(localClient.admin().indices().prepareCreate(localIndex).setSettings(indexSettings)); | ||
localClient.prepareIndex(localIndex).setSource("foo", "foo").get(); | ||
localClient.prepareIndex(localIndex).setSource("foo", "foobar").get(); | ||
localClient.admin().indices().prepareRefresh(localIndex).get(); | ||
|
||
String remoteIndex = "remote_test"; | ||
assertAcked(remoteClient.admin().indices().prepareCreate(remoteIndex).setSettings(indexSettings)); | ||
remoteClient.prepareIndex(remoteIndex).setSource("foo", "bar").get(); | ||
remoteClient.prepareIndex(remoteIndex).setSource("foo", "foobar").get(); | ||
remoteClient.prepareIndex(remoteIndex).setSource("foo", "zar").get(); | ||
remoteClient.admin().indices().prepareRefresh(remoteIndex).get(); | ||
|
||
// _terms_enum on a remote cluster | ||
TermsEnumRequest req = new TermsEnumRequest("remote_cluster:remote_test") | ||
.field("foo.keyword"); | ||
TermsEnumResponse response = client().execute(TermsEnumAction.INSTANCE, req).actionGet(); | ||
assertTrue(response.isComplete()); | ||
assertThat(response.getTerms().size(), equalTo(3)); | ||
assertThat(response.getTerms().get(0), equalTo("bar")); | ||
assertThat(response.getTerms().get(1), equalTo("foobar")); | ||
assertThat(response.getTerms().get(2), equalTo("zar")); | ||
|
||
// _terms_enum on mixed clusters (local + remote) | ||
req = new TermsEnumRequest("remote_cluster:remote_test", "local_test") | ||
.field("foo.keyword"); | ||
response = client().execute(TermsEnumAction.INSTANCE, req).actionGet(); | ||
assertTrue(response.isComplete()); | ||
assertThat(response.getTerms().size(), equalTo(4)); | ||
assertThat(response.getTerms().get(0), equalTo("bar")); | ||
assertThat(response.getTerms().get(1), equalTo("foo")); | ||
assertThat(response.getTerms().get(2), equalTo("foobar")); | ||
assertThat(response.getTerms().get(3), equalTo("zar")); | ||
|
||
req = new TermsEnumRequest("remote_cluster:remote_test", "local_test") | ||
.field("foo.keyword") | ||
.searchAfter("foobar"); | ||
response = client().execute(TermsEnumAction.INSTANCE, req).actionGet(); | ||
assertTrue(response.isComplete()); | ||
assertThat(response.getTerms().size(), equalTo(1)); | ||
assertThat(response.getTerms().get(0), equalTo("zar")); | ||
|
||
req = new TermsEnumRequest("remote_cluster:remote_test", "local_test") | ||
.field("foo.keyword") | ||
.searchAfter("bar"); | ||
response = client().execute(TermsEnumAction.INSTANCE, req).actionGet(); | ||
assertTrue(response.isComplete()); | ||
assertThat(response.getTerms().size(), equalTo(3)); | ||
assertThat(response.getTerms().get(0), equalTo("foo")); | ||
assertThat(response.getTerms().get(1), equalTo("foobar")); | ||
assertThat(response.getTerms().get(2), equalTo("zar")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.