Search: Search requests hangs when no indices exists, closes #209.

This commit is contained in:
kimchy 2010-06-05 01:36:24 +03:00
parent d0eb836c4a
commit bcbc0dd741
4 changed files with 32 additions and 1 deletions

View File

@ -52,7 +52,7 @@ public class SearchPhaseExecutionException extends ElasticSearchException {
private static final String buildMessage(String phaseName, String msg, ShardSearchFailure[] shardFailures) {
StringBuilder sb = new StringBuilder();
sb.append("Failed to execute [").append(phaseName).append("] ").append(msg);
sb.append("Failed to execute phase [").append(phaseName).append("], ").append(msg);
if (shardFailures != null && shardFailures.length > 0) {
sb.append("; shardFailures ");
for (ShardSearchFailure shardFailure : shardFailures) {

View File

@ -41,6 +41,7 @@ import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.util.settings.Settings;
import org.elasticsearch.util.trove.ExtTIntArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
@ -110,6 +111,11 @@ public abstract class TransportSearchTypeAction extends BaseAction<SearchRequest
shardsIts = indicesService.searchShards(clusterState, request.indices(), request.queryHint());
expectedSuccessfulOps = shardsIts.size();
expectedTotalOps = shardsIts.totalSizeActive();
if (expectedSuccessfulOps == 0) {
// not search shards to search on...
throw new SearchPhaseExecutionException("initial", "No indices / shards to search on, requested indices are " + Arrays.toString(request.indices()), buildShardFailures());
}
}
public void start() {

View File

@ -59,6 +59,16 @@ public class DocumentActionsTests extends AbstractNodesTests {
startNode("server2");
client1 = getClient1();
client2 = getClient2();
// no indices, check that simple operations fail
try {
client1.prepareCount("test").setQuery(termQuery("_type", "type1")).setOperationThreading(BroadcastOperationThreading.NO_THREADS).execute().actionGet();
assert false : "should fail";
} catch (Exception e) {
// all is well
}
client1.prepareCount().setQuery(termQuery("_type", "type1")).setOperationThreading(BroadcastOperationThreading.NO_THREADS).execute().actionGet();
createIndex();
}

View File

@ -58,6 +58,21 @@ public class SimpleIndicesBoostSearchTests extends AbstractNodesTests {
@Test
public void testIndicesBoost() throws Exception {
// execute a search before we create an index
try {
client.prepareSearch().setQuery(termQuery("test", "value")).execute().actionGet();
assert false : "should fail";
} catch (Exception e) {
// ignore, no indices
}
try {
client.prepareSearch("test").setQuery(termQuery("test", "value")).execute().actionGet();
assert false : "should fail";
} catch (Exception e) {
// ignore, no indices
}
client.admin().indices().create(createIndexRequest("test1")).actionGet();
client.admin().indices().create(createIndexRequest("test2")).actionGet();
client.index(indexRequest("test1").type("type1").id("1")