Skip to content

Commit

Permalink
Parent/child: Fixed parent/child not being able to be used in alias f…
Browse files Browse the repository at this point in the history
…ilters.

Closes elastic#8628
  • Loading branch information
martijnvg committed Nov 25, 2014
1 parent 85a3971 commit 6f4eaa2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
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

0 comments on commit 6f4eaa2

Please sign in to comment.