Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed p/c filters not being able to be used in alias filters. #8649

Merged
merged 1 commit into from Nov 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -35,7 +35,9 @@ private QueryParserUtils() {
public static void ensureNotDeleteByQuery(String name, QueryParseContext parseContext) {
SearchContext context = SearchContext.current();
if (context == null) {
throw new QueryParsingException(parseContext.index(), "[" + name + "] query and filter requires a search context");
// We can't do the api check, because there is no search context.
// Because the delete by query shard transport action sets the search context this isn't an issue.
return;
}

if (TransportShardDeleteByQueryAction.DELETE_BY_QUERY_API.equals(context.source())) {
Expand Down
25 changes: 18 additions & 7 deletions src/test/java/org/elasticsearch/aliases/IndexAliasesTests.java
Expand Up @@ -57,6 +57,7 @@
import static org.elasticsearch.client.Requests.indexRequest;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.elasticsearch.index.query.FilterBuilders.*;
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
import static org.elasticsearch.index.query.QueryBuilders.rangeQuery;
import static org.elasticsearch.test.hamcrest.CollectionAssertions.hasKey;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
Expand Down Expand Up @@ -883,12 +884,12 @@ public void testCreateIndexWithAliases() throws Exception {
@Test
public void testCreateIndexWithAliasesInSource() throws Exception {
assertAcked(prepareCreate("test").setSource("{\n" +
" \"aliases\" : {\n" +
" \"alias1\" : {},\n" +
" \"alias2\" : {\"filter\" : {\"match_all\": {}}},\n" +
" \"alias3\" : { \"index_routing\" : \"index\", \"search_routing\" : \"search\"}\n" +
" }\n" +
"}"));
" \"aliases\" : {\n" +
" \"alias1\" : {},\n" +
" \"alias2\" : {\"filter\" : {\"match_all\": {}}},\n" +
" \"alias3\" : { \"index_routing\" : \"index\", \"search_routing\" : \"search\"}\n" +
" }\n" +
"}"));

checkAliases();
}
Expand Down Expand Up @@ -975,7 +976,17 @@ public void testAliasFilterWithNowInRangeFilterAndQuery() throws Exception {
}
}
}


@Test
public void testAliasesFilterWithHasChildQuery() throws Exception {
assertAcked(prepareCreate("my-index")
.addMapping("parent")
.addMapping("child", "_parent", "type=parent")
);
assertAcked(admin().indices().prepareAliases().addAlias("my-index", "filter1", hasChildFilter("child", matchAllQuery())));
assertAcked(admin().indices().prepareAliases().addAlias("my-index", "filter2", hasParentFilter("child", matchAllQuery())));
}

private void checkAliases() {
GetAliasesResponse getAliasesResponse = admin().indices().prepareGetAliases("alias1").get();
assertThat(getAliasesResponse.getAliases().get("test").size(), equalTo(1));
Expand Down