Better handling of /_all/_search when no indices exist

closes #3710
This commit is contained in:
Shay Banon 2013-09-16 23:32:17 +02:00
parent c8a72d9768
commit 8f7e3c8b53
2 changed files with 9 additions and 15 deletions

View File

@ -42,11 +42,11 @@ import org.elasticsearch.search.SearchShardTarget;
import org.elasticsearch.search.action.SearchServiceListener; import org.elasticsearch.search.action.SearchServiceListener;
import org.elasticsearch.search.action.SearchServiceTransportAction; import org.elasticsearch.search.action.SearchServiceTransportAction;
import org.elasticsearch.search.controller.SearchPhaseController; import org.elasticsearch.search.controller.SearchPhaseController;
import org.elasticsearch.search.internal.InternalSearchResponse;
import org.elasticsearch.search.internal.ShardSearchRequest; import org.elasticsearch.search.internal.ShardSearchRequest;
import org.elasticsearch.search.query.QuerySearchResultProvider; import org.elasticsearch.search.query.QuerySearchResultProvider;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -119,15 +119,15 @@ public abstract class TransportSearchTypeAction extends TransportAction<SearchRe
// we need to add 1 for non active partition, since we count it in the total! // we need to add 1 for non active partition, since we count it in the total!
expectedTotalOps = shardsIts.totalSizeWith1ForEmpty(); expectedTotalOps = shardsIts.totalSizeWith1ForEmpty();
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());
}
firstResults = new AtomicArray<FirstResult>(shardsIts.size()); firstResults = new AtomicArray<FirstResult>(shardsIts.size());
} }
public void start() { public void start() {
if (expectedSuccessfulOps == 0) {
// no search shards to search on, bail with empty response (it happens with search across _all with no indices around and consistent with broadcast operations)
listener.onResponse(new SearchResponse(InternalSearchResponse.EMPTY, null, 0, 0, System.currentTimeMillis() - startTime, ShardSearchFailure.EMPTY_ARRAY));
return;
}
request.beforeStart(); request.beforeStart();
// count the local operations, and perform the non local ones // count the local operations, and perform the non local ones
int localOperations = 0; int localOperations = 0;

View File

@ -19,19 +19,19 @@
package org.elasticsearch.search.indicesboost; package org.elasticsearch.search.indicesboost;
import org.elasticsearch.AbstractSharedClusterTest;
import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType; import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.AbstractSharedClusterTest; import org.elasticsearch.test.hamcrest.ElasticsearchAssertions;
import org.junit.Test; import org.junit.Test;
import static org.elasticsearch.client.Requests.*; import static org.elasticsearch.client.Requests.*;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.index.query.QueryBuilders.termQuery; import static org.elasticsearch.index.query.QueryBuilders.termQuery;
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource; import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
/** /**
@ -46,13 +46,7 @@ public class SimpleIndicesBoostSearchTests extends AbstractSharedClusterTest {
@Test @Test
public void testIndicesBoost() throws Exception { public void testIndicesBoost() throws Exception {
// execute a search before we create an index ElasticsearchAssertions.assertHitCount(client().prepareSearch().setQuery(termQuery("test", "value")).get(), 0);
try {
client().prepareSearch().setQuery(termQuery("test", "value")).execute().actionGet();
assert false : "should fail";
} catch (Exception e) {
// ignore, no indices
}
try { try {
client().prepareSearch("test").setQuery(termQuery("test", "value")).execute().actionGet(); client().prepareSearch("test").setQuery(termQuery("test", "value")).execute().actionGet();