Skip to content

Commit 404a8f2

Browse files
committed
optimize single alias lookup
1 parent 3d5d25b commit 404a8f2

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

modules/elasticsearch/src/main/java/org/elasticsearch/index/aliases/IndexAliasesService.java

+27-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919

2020
package org.elasticsearch.index.aliases;
2121

22-
import org.apache.lucene.search.*;
22+
import org.apache.lucene.search.BooleanClause;
23+
import org.apache.lucene.search.Filter;
24+
import org.apache.lucene.search.FilterClause;
2325
import org.elasticsearch.common.Nullable;
2426
import org.elasticsearch.common.collect.ImmutableMap;
2527
import org.elasticsearch.common.collect.UnmodifiableIterator;
@@ -39,8 +41,8 @@
3941
import java.io.IOException;
4042
import java.util.List;
4143

42-
import static org.elasticsearch.common.collect.Lists.newArrayList;
43-
import static org.elasticsearch.common.collect.MapBuilder.newMapBuilder;
44+
import static org.elasticsearch.common.collect.Lists.*;
45+
import static org.elasticsearch.common.collect.MapBuilder.*;
4446

4547
/**
4648
* @author imotov
@@ -70,7 +72,29 @@ public void add(String alias, @Nullable CompressedString filter) {
7072
add(new IndexAlias(alias, filter, parse(alias, filter)));
7173
}
7274

75+
/**
76+
* Returns the filter associated with a possibly aliased indices.
77+
*
78+
* <p>Returns <tt>null</tt> if no filtering is required. Note, if no alias if found for the provided value
79+
* then no filtering is done.</p>
80+
*/
7381
public Filter aliasFilter(String... indices) {
82+
if (indices == null) {
83+
return null;
84+
}
85+
// optimize for the most common single index/alias scenario
86+
if (indices.length == 1) {
87+
String alias = indices[0];
88+
// The list contains the index itself - no filtering needed
89+
if (alias.equals(index.name())) {
90+
return null;
91+
}
92+
IndexAlias indexAlias = aliases.get(alias);
93+
if (indexAlias == null) {
94+
return null;
95+
}
96+
return indexAlias.parsedFilter();
97+
}
7498
List<Filter> filters = null;
7599
for (String alias : indices) {
76100
// The list contains the index itself - no filtering needed

0 commit comments

Comments
 (0)