From e3766d28288ed2e0f3cd098e7a6b8c22de3a0fa6 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Fri, 5 May 2017 16:40:04 +0200 Subject: [PATCH] Expand cross cluster search indices for search requests to the concrete index or to it's aliases (#24502) This change will expand the shard level request to the actual concrete index or to the aliases that expanded to the concrete index to ensure shard level requests won't see wildcard expressions as their original indices --- .../action/search/TransportSearchAction.java | 13 ++++++++----- .../org/elasticsearch/common/util/ArrayUtils.java | 1 - .../action/search/TransportSearchActionTests.java | 15 +++++++++------ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java b/core/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java index 9c8d1a879b1..f65597a966b 100644 --- a/core/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java +++ b/core/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java @@ -220,11 +220,6 @@ public class TransportSearchAction extends HandledTransportAction { diff --git a/core/src/main/java/org/elasticsearch/common/util/ArrayUtils.java b/core/src/main/java/org/elasticsearch/common/util/ArrayUtils.java index de23663b3e9..20c12d564da 100644 --- a/core/src/main/java/org/elasticsearch/common/util/ArrayUtils.java +++ b/core/src/main/java/org/elasticsearch/common/util/ArrayUtils.java @@ -84,5 +84,4 @@ public class ArrayUtils { System.arraycopy(other, 0, target, one.length, other.length); return target; } - } diff --git a/core/src/test/java/org/elasticsearch/action/search/TransportSearchActionTests.java b/core/src/test/java/org/elasticsearch/action/search/TransportSearchActionTests.java index f34f4313fd6..7491eda8fd7 100644 --- a/core/src/test/java/org/elasticsearch/action/search/TransportSearchActionTests.java +++ b/core/src/test/java/org/elasticsearch/action/search/TransportSearchActionTests.java @@ -64,7 +64,6 @@ public class TransportSearchActionTests extends ESTestCase { ThreadPool.terminate(threadPool, 10, TimeUnit.SECONDS); } - public void testMergeShardsIterators() throws IOException { List localShardIterators = new ArrayList<>(); { @@ -159,7 +158,8 @@ public class TransportSearchActionTests extends ESTestCase { new DiscoveryNode("node2", buildNewFakeTransportAddress(), Version.CURRENT) }; Map indicesAndAliases = new HashMap<>(); - indicesAndAliases.put("foo", new AliasFilter(new TermsQueryBuilder("foo", "bar"), Strings.EMPTY_ARRAY)); + indicesAndAliases.put("foo", new AliasFilter(new TermsQueryBuilder("foo", "bar"), "some_alias_for_foo", + "some_other_foo_alias")); indicesAndAliases.put("bar", new AliasFilter(new MatchAllQueryBuilder(), Strings.EMPTY_ARRAY)); ClusterSearchShardsGroup[] groups = new ClusterSearchShardsGroup[] { new ClusterSearchShardsGroup(new ShardId("foo", "foo_id", 0), @@ -180,7 +180,9 @@ public class TransportSearchActionTests extends ESTestCase { new ClusterSearchShardsGroup(new ShardId("xyz", "xyz_id", 0), new ShardRouting[] {TestShardRouting.newShardRouting("xyz", 0, "node3", true, ShardRoutingState.STARTED)}) }; - searchShardsResponseMap.put("test_cluster_2", new ClusterSearchShardsResponse(groups2, nodes2, null)); + Map filter = new HashMap<>(); + filter.put("xyz", new AliasFilter(null, "some_alias_for_xyz")); + searchShardsResponseMap.put("test_cluster_2", new ClusterSearchShardsResponse(groups2, nodes2, filter)); Map remoteIndicesByCluster = new HashMap<>(); remoteIndicesByCluster.put("test_cluster_1", @@ -193,7 +195,8 @@ public class TransportSearchActionTests extends ESTestCase { assertEquals(4, iteratorList.size()); for (SearchShardIterator iterator : iteratorList) { if (iterator.shardId().getIndexName().endsWith("foo")) { - assertArrayEquals(new String[]{"fo*", "ba*"}, iterator.getOriginalIndices().indices()); + assertArrayEquals(new String[]{"some_alias_for_foo", "some_other_foo_alias"}, + iterator.getOriginalIndices().indices()); assertTrue(iterator.shardId().getId() == 0 || iterator.shardId().getId() == 1); assertEquals("test_cluster_1:foo", iterator.shardId().getIndexName()); ShardRouting shardRouting = iterator.nextOrNull(); @@ -204,7 +207,7 @@ public class TransportSearchActionTests extends ESTestCase { assertEquals(shardRouting.getIndexName(), "foo"); assertNull(iterator.nextOrNull()); } else if (iterator.shardId().getIndexName().endsWith("bar")) { - assertArrayEquals(new String[]{"fo*", "ba*"}, iterator.getOriginalIndices().indices()); + assertArrayEquals(new String[]{"bar"}, iterator.getOriginalIndices().indices()); assertEquals(0, iterator.shardId().getId()); assertEquals("test_cluster_1:bar", iterator.shardId().getIndexName()); ShardRouting shardRouting = iterator.nextOrNull(); @@ -215,7 +218,7 @@ public class TransportSearchActionTests extends ESTestCase { assertEquals(shardRouting.getIndexName(), "bar"); assertNull(iterator.nextOrNull()); } else if (iterator.shardId().getIndexName().endsWith("xyz")) { - assertArrayEquals(new String[]{"x*"}, iterator.getOriginalIndices().indices()); + assertArrayEquals(new String[]{"some_alias_for_xyz"}, iterator.getOriginalIndices().indices()); assertEquals(0, iterator.shardId().getId()); assertEquals("test_cluster_2:xyz", iterator.shardId().getIndexName()); ShardRouting shardRouting = iterator.nextOrNull();