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

Fix bug when searching concrete and routing aliased indices fix #2682 #2683

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ public GroupShardsIterator searchShards(ClusterState clusterState, String[] indi
set.add(iterator);
}
}
} else {
for (IndexShardRoutingTable indexShard : indexRouting) {
ShardIterator iterator = preferenceActiveShardIterator(indexShard, clusterState.nodes().localNodeId(), clusterState.nodes(), preference);
if (iterator != null) {
set.add(iterator);
}
}
}
}
return new GroupShardsIterator(set);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,34 @@ public void testAliasSearchRoutingWithTwoIndices() throws Exception {
}
}

@Test
public void testAliasSearchRoutingWithConcreteAndAliasedIndices() throws Exception {
try {
client.admin().indices().prepareDelete("index").execute().actionGet();
client.admin().indices().prepareDelete("index_2").execute().actionGet();
} catch (Exception e) {
// ignore
}
client.admin().indices().prepareCreate("index").execute().actionGet();
client.admin().indices().prepareCreate("index_2").execute().actionGet();
client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();

client.admin().indices().prepareAliases()
.addAliasAction(newAddAliasAction("index", "index_1").routing("1"))
.execute().actionGet();

logger.info("--> indexing on index_1 which is an alias for index with routing [1]");
client.prepareIndex("index_1", "type1", "1").setSource("field", "value1").setRefresh(true).execute().actionGet();
logger.info("--> indexing on index_2 which is a concrete index");
client.prepareIndex("index_2", "type2", "2").setSource("field", "value2").setRefresh(true).execute().actionGet();


logger.info("--> search all on index_* should find two");
for (int i = 0; i < 5; i++) {
assertThat(client.prepareSearch("index_*").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(2l));
}
}

@Test
public void testRequiredRoutingMappingWithAlias() throws Exception {
try {
Expand Down