Alias filter not applied when using 'multi-index' syntax with wild card in URL

closes #3677
This commit is contained in:
Shay Banon 2013-09-17 13:30:40 +02:00
parent 4013980b11
commit cf30cb1caa
2 changed files with 25 additions and 6 deletions

View File

@ -655,7 +655,15 @@ public class MetaData implements Iterable<IndexMetaData> {
return lst.values[0];
}
/**
* Converts a list of indices or aliases wildcards, and special +/- signs, into their respective full matches. It
* won't convert only to indices, but also to aliases. For example, alias_* will expand to alias_1 and alias_2, not
* to the respective indices those aliases point to.
*/
public String[] convertFromWildcards(String[] aliasesOrIndices, boolean wildcardOnlyOpen, IgnoreIndices ignoreIndices) {
if (aliasesOrIndices == null) {
return null;
}
Set<String> result = null;
for (int i = 0; i < aliasesOrIndices.length; i++) {
String aliasOrIndex = aliasesOrIndices[i];
@ -788,6 +796,9 @@ public class MetaData implements Iterable<IndexMetaData> {
* the index itself - null is returned. Returns <tt>null</tt> if no filtering is required.</p>
*/
public String[] filteringAliases(String index, String... indicesOrAliases) {
// expand the aliases wildcard
indicesOrAliases = convertFromWildcards(indicesOrAliases, true, IgnoreIndices.MISSING);
if (isAllIndices(indicesOrAliases)) {
return null;
}

View File

@ -19,6 +19,7 @@
package org.elasticsearch.aliases;
import org.elasticsearch.AbstractSharedClusterTest;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
@ -42,7 +43,6 @@ import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.facet.FacetBuilders;
import org.elasticsearch.search.facet.terms.TermsFacet;
import org.elasticsearch.search.sort.SortOrder;
import org.elasticsearch.AbstractSharedClusterTest;
import org.junit.Test;
import java.util.Set;
@ -189,6 +189,10 @@ public class IndexAliasesTests extends AbstractSharedClusterTest {
SearchResponse searchResponse = client().prepareSearch("foos").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
assertHits(searchResponse.getHits(), "1");
logger.info("--> checking single filtering alias wildcard search");
searchResponse = client().prepareSearch("fo*").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
assertHits(searchResponse.getHits(), "1");
searchResponse = client().prepareSearch("tests").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
assertHits(searchResponse.getHits(), "1", "2", "3");
@ -228,6 +232,10 @@ public class IndexAliasesTests extends AbstractSharedClusterTest {
logger.info("--> checking index and filtering alias search");
searchResponse = client().prepareSearch("test", "foos").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
assertHits(searchResponse.getHits(), "1", "2", "3", "4");
logger.info("--> checking index and alias wildcard search");
searchResponse = client().prepareSearch("te*", "fo*").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
assertHits(searchResponse.getHits(), "1", "2", "3", "4");
}
@Test
@ -816,7 +824,7 @@ public class IndexAliasesTests extends AbstractSharedClusterTest {
client().admin().indices().prepareAliases().addAliasAction(AliasAction.newAddAliasAction(null, null))
.execute().actionGet();
assertTrue("Should throw " + ActionRequestValidationException.class.getSimpleName(), false);
} catch(ActionRequestValidationException e) {
} catch (ActionRequestValidationException e) {
assertThat(e.validationErrors(), notNullValue());
assertThat(e.validationErrors().size(), equalTo(2));
}
@ -826,9 +834,9 @@ public class IndexAliasesTests extends AbstractSharedClusterTest {
public void testAddAliasEmptyAliasEmptyIndex() {
try {
client().admin().indices().prepareAliases().addAliasAction(AliasAction.newAddAliasAction("", ""))
.execute().actionGet();
.execute().actionGet();
assertTrue("Should throw " + ActionRequestValidationException.class.getSimpleName(), false);
} catch(ActionRequestValidationException e) {
} catch (ActionRequestValidationException e) {
assertThat(e.validationErrors(), notNullValue());
assertThat(e.validationErrors().size(), equalTo(2));
}
@ -864,7 +872,7 @@ public class IndexAliasesTests extends AbstractSharedClusterTest {
client().admin().indices().prepareAliases().addAliasAction(AliasAction.newAddAliasAction(null, null))
.execute().actionGet();
assertTrue("Should throw " + ActionRequestValidationException.class.getSimpleName(), false);
} catch(ActionRequestValidationException e) {
} catch (ActionRequestValidationException e) {
assertThat(e.validationErrors(), notNullValue());
assertThat(e.validationErrors().size(), equalTo(2));
}
@ -876,7 +884,7 @@ public class IndexAliasesTests extends AbstractSharedClusterTest {
client().admin().indices().prepareAliases().addAliasAction(AliasAction.newAddAliasAction("", ""))
.execute().actionGet();
assertTrue("Should throw " + ActionRequestValidationException.class.getSimpleName(), false);
} catch(ActionRequestValidationException e) {
} catch (ActionRequestValidationException e) {
assertThat(e.validationErrors(), notNullValue());
assertThat(e.validationErrors().size(), equalTo(2));
}