Skip to content

Commit

Permalink
Fix bug when searching concrete and routing aliased indices
Browse files Browse the repository at this point in the history
Closes #2683
  • Loading branch information
Paikan authored and s1monw committed Mar 3, 2013
1 parent 23c3222 commit d9b6f2e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
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

0 comments on commit d9b6f2e

Please sign in to comment.