|
19 | 19 |
|
20 | 20 | package org.elasticsearch.index.aliases;
|
21 | 21 |
|
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; |
23 | 25 | import org.elasticsearch.common.Nullable;
|
24 | 26 | import org.elasticsearch.common.collect.ImmutableMap;
|
25 | 27 | import org.elasticsearch.common.collect.UnmodifiableIterator;
|
|
39 | 41 | import java.io.IOException;
|
40 | 42 | import java.util.List;
|
41 | 43 |
|
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.*; |
44 | 46 |
|
45 | 47 | /**
|
46 | 48 | * @author imotov
|
@@ -70,7 +72,29 @@ public void add(String alias, @Nullable CompressedString filter) {
|
70 | 72 | add(new IndexAlias(alias, filter, parse(alias, filter)));
|
71 | 73 | }
|
72 | 74 |
|
| 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 | + */ |
73 | 81 | 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 | + } |
74 | 98 | List<Filter> filters = null;
|
75 | 99 | for (String alias : indices) {
|
76 | 100 | // The list contains the index itself - no filtering needed
|
|
0 commit comments