Ver código fonte

cut over to use : instead of | for cross cluster search

Simon Willnauer 8 anos atrás
pai
commit
349ea0f9b6

+ 1 - 1
core/src/main/java/org/elasticsearch/action/search/RemoteClusterService.java

@@ -92,7 +92,7 @@ public final class RemoteClusterService extends AbstractComponent implements Clo
     public static final Setting<String> REMOTE_NODE_ATTRIBUTE = Setting.simpleString("search.remote.node_attribute",
         Setting.Property.NodeScope);
 
-    private static final char REMOTE_CLUSTER_INDEX_SEPARATOR = '|';
+    private static final char REMOTE_CLUSTER_INDEX_SEPARATOR = ':';
 
     private final TransportService transportService;
     private final int numRemoteConnections;

+ 5 - 1
core/src/test/java/org/elasticsearch/action/search/RemoteClusterConnectionTests.java

@@ -75,7 +75,11 @@ public class RemoteClusterConnectionTests extends ESTestCase {
         ThreadPool.terminate(threadPool, 10, TimeUnit.SECONDS);
     }
 
-    public MockTransportService startTransport(String id, List<DiscoveryNode> knownNodes, Version version) {
+    private MockTransportService startTransport(String id, List<DiscoveryNode> knownNodes, Version version) {
+        return startTransport(id, knownNodes, version, threadPool);
+    }
+
+    public static MockTransportService startTransport(String id, List<DiscoveryNode> knownNodes, Version version, ThreadPool threadPool) {
         boolean success = false;
         MockTransportService newService = MockTransportService.createNewService(Settings.EMPTY, version, threadPool, null);
         try {

+ 61 - 0
core/src/test/java/org/elasticsearch/action/search/RemoteClusterServiceTests.java

@@ -19,18 +19,48 @@
 package org.elasticsearch.action.search;
 
 import org.elasticsearch.Version;
+import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsAction;
+import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsGroup;
+import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsRequest;
+import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsResponse;
+import org.elasticsearch.action.admin.cluster.state.ClusterStateAction;
+import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
+import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
+import org.elasticsearch.cluster.ClusterName;
+import org.elasticsearch.cluster.ClusterState;
 import org.elasticsearch.cluster.node.DiscoveryNode;
+import org.elasticsearch.cluster.node.DiscoveryNodes;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.common.transport.TransportAddress;
 import org.elasticsearch.test.ESTestCase;
+import org.elasticsearch.test.transport.MockTransportService;
+import org.elasticsearch.threadpool.TestThreadPool;
+import org.elasticsearch.threadpool.ThreadPool;
 
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.TimeUnit;
 
 public class RemoteClusterServiceTests extends ESTestCase {
 
+    private final ThreadPool threadPool = new TestThreadPool(getClass().getName());
+
+    @Override
+    public void tearDown() throws Exception {
+        super.tearDown();
+        ThreadPool.terminate(threadPool, 10, TimeUnit.SECONDS);
+    }
+
+    private MockTransportService startTransport(String id, List<DiscoveryNode> knownNodes, Version version) {
+        return RemoteClusterConnectionTests.startTransport(id, knownNodes, version, threadPool);
+    }
+
     public void testRemoteClusterSeedSetting() {
         // simple validation
         RemoteClusterService.REMOTE_CLUSTERS_SEEDS.get(Settings.builder()
@@ -64,4 +94,35 @@ public class RemoteClusterServiceTests extends ESTestCase {
         assertEquals(bar.getId(), "bar#[::1]:9090");
         assertEquals(bar.getVersion(), Version.CURRENT.minimumCompatibilityVersion());
     }
+
+
+    public void testFilterIndices() {
+        List<DiscoveryNode> knownNodes = new CopyOnWriteArrayList<>();
+        try (MockTransportService seedTransport = startTransport("cluster_1_node", knownNodes, Version.CURRENT);
+             MockTransportService otherSeedTransport = startTransport("cluster_2_node", knownNodes, Version.CURRENT)) {
+            DiscoveryNode seedNode = seedTransport.getLocalDiscoNode();
+            DiscoveryNode otherSeedNode = otherSeedTransport.getLocalDiscoNode();
+            knownNodes.add(seedTransport.getLocalDiscoNode());
+            knownNodes.add(otherSeedTransport.getLocalDiscoNode());
+            Collections.shuffle(knownNodes, random());
+
+            try (MockTransportService transportService = MockTransportService.createNewService(Settings.EMPTY, Version.CURRENT, threadPool,
+                null)) {
+                transportService.start();
+                transportService.acceptIncomingRequests();
+                Settings.Builder builder = Settings.builder();
+                builder.putArray("search.remote.seeds.cluster_1", seedNode.getAddress().toString());
+                builder.putArray("search.remote.seeds.cluster_2", otherSeedNode.getAddress().toString());
+                RemoteClusterService service = new RemoteClusterService(builder.build(), transportService);
+                service.initializeRemoteClusters();
+                Map<String, List<String>> perClusterIndices = new HashMap<>();
+                String[] localIndices = service.filterIndices(perClusterIndices, new String[]{"foo:bar", "cluster_1:bar",
+                    "cluster_2:foo:bar", "cluster_1:test", "cluster_2:foo*", "foo"});
+                assertArrayEquals(new String[]{"foo:bar", "foo"}, localIndices);
+                assertEquals(2, perClusterIndices.size());
+                assertEquals(Arrays.asList("bar", "test"), perClusterIndices.get("cluster_1"));
+                assertEquals(Arrays.asList("foo:bar", "foo*"), perClusterIndices.get("cluster_2"));
+            }
+        }
+    }
 }

+ 5 - 5
docs/reference/modules/cross-cluster-search.asciidoc

@@ -35,11 +35,11 @@ search:
 === Using cross cluster search
 
 To search the `twitter` index on remote cluster `cluster_1` the index name must be prefixed with the cluster name
-separated by a `|` character:
+separated by a `:` character:
 
 [source,js]
 --------------------------------------------------
-POST /cluster_1|twitter/tweet/_search
+POST /cluster_one:twitter/tweet/_search
 {
     "match_all": {}
 }
@@ -50,7 +50,7 @@ In contrast to the `tribe` feature cross cluster search can also search indices
 
 [source,js]
 --------------------------------------------------
-POST /cluster_1|twitter,twitter/tweet/_search
+POST /cluster_one:twitter,twitter/tweet/_search
 {
     "match_all": {}
 }
@@ -75,7 +75,7 @@ will be prefixed with it's remote clusters name:
     "max_score" : 1.0,
     "hits" : [
       {
-        "_index" : "cluster_1|twitter",
+        "_index" : "cluster_one:twitter",
         "_type" : "tweet",
         "_id" : "1",
         "_score" : 1.0,
@@ -86,7 +86,7 @@ will be prefixed with it's remote clusters name:
         }
       },
       {
-        "_index" : "cluster_1|twitter",
+        "_index" : "twitter",
         "_type" : "tweet",
         "_id" : "1",
         "_score" : 1.0,

+ 9 - 9
qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/10_basic.yaml

@@ -27,7 +27,7 @@
 
   - do:
     search:
-      index: test_index,my_remote_cluster|test_index
+      index: test_index,my_remote_cluster:test_index
       body:
         aggs:
           cluster:
@@ -44,7 +44,7 @@
 
   - do:
     search:
-      index: test_index,my_remote_cluster|test_index
+      index: test_index,my_remote_cluster:test_index
       body:
         query:
           term:
@@ -56,14 +56,14 @@
 
   - match: { _shards.total: 5 }
   - match: { hits.total: 6}
-  - match: { hits.hits.0._index: "my_remote_cluster|test_index"}
+  - match: { hits.hits.0._index: "my_remote_cluster:test_index"}
   - length: { aggregations.cluster.buckets: 1 }
   - match: { aggregations.cluster.buckets.0.key: "remote_cluster" }
   - match: { aggregations.cluster.buckets.0.doc_count: 6 }
 
   - do:
     search:
-      index: my_remote_cluster|test_index
+      index: my_remote_cluster:test_index
       body:
         aggs:
           cluster:
@@ -72,7 +72,7 @@
 
   - match: { _shards.total: 3 }
   - match: { hits.total: 6}
-  - match: { hits.hits.0._index: "my_remote_cluster|test_index"}
+  - match: { hits.hits.0._index: "my_remote_cluster:test_index"}
   - length: { aggregations.cluster.buckets: 1 }
   - match: { aggregations.cluster.buckets.0.key: "remote_cluster" }
   - match: { aggregations.cluster.buckets.0.doc_count: 6 }
@@ -112,20 +112,20 @@
 
   - do:
     search:
-      index: test_remote_cluster|test_index
+      index: test_remote_cluster:test_index
 
   - match: { _shards.total: 3 }
   - match: { hits.total: 6 }
-  - match: { hits.hits.0._index: "test_remote_cluster|test_index" }
+  - match: { hits.hits.0._index: "test_remote_cluster:test_index" }
 
 ---
 "Search an filtered alias on the remote cluster":
 
   - do:
     search:
-      index: my_remote_cluster|aliased_test_index
+      index: my_remote_cluster:aliased_test_index
 
   - match: { _shards.total: 3 }
   - match: { hits.total: 2 }
   - match: { hits.hits.0._source.filter_field: 1 }
-  - match: { hits.hits.0._index: "my_remote_cluster|test_index" }
+  - match: { hits.hits.0._index: "my_remote_cluster:test_index" }