Skip to content

Commit 02a9287

Browse files
committed
Revert change that does not return all indices if a specific alias is requested via get alias api. (#28294)
Reopens #27763
1 parent 394a1dd commit 02a9287

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

server/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,8 @@ public ImmutableOpenMap<String, List<AliasMetaData>> findAliases(final String[]
276276
if (!filteredValues.isEmpty()) {
277277
// Make the list order deterministic
278278
CollectionUtil.timSort(filteredValues, Comparator.comparing(AliasMetaData::alias));
279-
mapBuilder.put(index, Collections.unmodifiableList(filteredValues));
280-
} else if (matchAllAliases) {
281-
// in case all aliases are requested then it is desired to return the concrete index with no aliases (#25114):
282-
mapBuilder.put(index, Collections.emptyList());
283279
}
280+
mapBuilder.put(index, Collections.unmodifiableList(filteredValues));
284281
}
285282
return mapBuilder.build();
286283
}

server/src/test/java/org/elasticsearch/aliases/IndexAliasesIT.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -570,20 +570,24 @@ public void testIndicesGetAliases() throws Exception {
570570
logger.info("--> getting alias1");
571571
GetAliasesResponse getResponse = admin().indices().prepareGetAliases("alias1").get();
572572
assertThat(getResponse, notNullValue());
573-
assertThat(getResponse.getAliases().size(), equalTo(1));
573+
assertThat(getResponse.getAliases().size(), equalTo(5));
574574
assertThat(getResponse.getAliases().get("foobar").size(), equalTo(1));
575575
assertThat(getResponse.getAliases().get("foobar").get(0), notNullValue());
576576
assertThat(getResponse.getAliases().get("foobar").get(0).alias(), equalTo("alias1"));
577577
assertThat(getResponse.getAliases().get("foobar").get(0).getFilter(), nullValue());
578578
assertThat(getResponse.getAliases().get("foobar").get(0).getIndexRouting(), nullValue());
579579
assertThat(getResponse.getAliases().get("foobar").get(0).getSearchRouting(), nullValue());
580+
assertTrue(getResponse.getAliases().get("test").isEmpty());
581+
assertTrue(getResponse.getAliases().get("test123").isEmpty());
582+
assertTrue(getResponse.getAliases().get("foobarbaz").isEmpty());
583+
assertTrue(getResponse.getAliases().get("bazbar").isEmpty());
580584
AliasesExistResponse existsResponse = admin().indices().prepareAliasesExist("alias1").get();
581585
assertThat(existsResponse.exists(), equalTo(true));
582586

583587
logger.info("--> getting all aliases that start with alias*");
584588
getResponse = admin().indices().prepareGetAliases("alias*").get();
585589
assertThat(getResponse, notNullValue());
586-
assertThat(getResponse.getAliases().size(), equalTo(1));
590+
assertThat(getResponse.getAliases().size(), equalTo(5));
587591
assertThat(getResponse.getAliases().get("foobar").size(), equalTo(2));
588592
assertThat(getResponse.getAliases().get("foobar").get(0), notNullValue());
589593
assertThat(getResponse.getAliases().get("foobar").get(0).alias(), equalTo("alias1"));
@@ -595,6 +599,10 @@ public void testIndicesGetAliases() throws Exception {
595599
assertThat(getResponse.getAliases().get("foobar").get(1).getFilter(), nullValue());
596600
assertThat(getResponse.getAliases().get("foobar").get(1).getIndexRouting(), nullValue());
597601
assertThat(getResponse.getAliases().get("foobar").get(1).getSearchRouting(), nullValue());
602+
assertTrue(getResponse.getAliases().get("test").isEmpty());
603+
assertTrue(getResponse.getAliases().get("test123").isEmpty());
604+
assertTrue(getResponse.getAliases().get("foobarbaz").isEmpty());
605+
assertTrue(getResponse.getAliases().get("bazbar").isEmpty());
598606
existsResponse = admin().indices().prepareAliasesExist("alias*").get();
599607
assertThat(existsResponse.exists(), equalTo(true));
600608

@@ -679,12 +687,13 @@ public void testIndicesGetAliases() throws Exception {
679687
logger.info("--> getting f* for index *bar");
680688
getResponse = admin().indices().prepareGetAliases("f*").addIndices("*bar").get();
681689
assertThat(getResponse, notNullValue());
682-
assertThat(getResponse.getAliases().size(), equalTo(1));
690+
assertThat(getResponse.getAliases().size(), equalTo(2));
683691
assertThat(getResponse.getAliases().get("foobar").get(0), notNullValue());
684692
assertThat(getResponse.getAliases().get("foobar").get(0).alias(), equalTo("foo"));
685693
assertThat(getResponse.getAliases().get("foobar").get(0).getFilter(), nullValue());
686694
assertThat(getResponse.getAliases().get("foobar").get(0).getIndexRouting(), nullValue());
687695
assertThat(getResponse.getAliases().get("foobar").get(0).getSearchRouting(), nullValue());
696+
assertTrue(getResponse.getAliases().get("bazbar").isEmpty());
688697
existsResponse = admin().indices().prepareAliasesExist("f*")
689698
.addIndices("*bar").get();
690699
assertThat(existsResponse.exists(), equalTo(true));
@@ -693,13 +702,14 @@ public void testIndicesGetAliases() throws Exception {
693702
logger.info("--> getting f* for index *bac");
694703
getResponse = admin().indices().prepareGetAliases("foo").addIndices("*bac").get();
695704
assertThat(getResponse, notNullValue());
696-
assertThat(getResponse.getAliases().size(), equalTo(1));
705+
assertThat(getResponse.getAliases().size(), equalTo(2));
697706
assertThat(getResponse.getAliases().get("foobar").size(), equalTo(1));
698707
assertThat(getResponse.getAliases().get("foobar").get(0), notNullValue());
699708
assertThat(getResponse.getAliases().get("foobar").get(0).alias(), equalTo("foo"));
700709
assertThat(getResponse.getAliases().get("foobar").get(0).getFilter(), nullValue());
701710
assertThat(getResponse.getAliases().get("foobar").get(0).getIndexRouting(), nullValue());
702711
assertThat(getResponse.getAliases().get("foobar").get(0).getSearchRouting(), nullValue());
712+
assertTrue(getResponse.getAliases().get("bazbar").isEmpty());
703713
existsResponse = admin().indices().prepareAliasesExist("foo")
704714
.addIndices("*bac").get();
705715
assertThat(existsResponse.exists(), equalTo(true));

0 commit comments

Comments
 (0)