diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/count/CountRequest.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/count/CountRequest.java index 7bdd6cc9ebb..e2b25f50c1b 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/count/CountRequest.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/count/CountRequest.java @@ -22,7 +22,6 @@ package org.elasticsearch.action.count; import org.apache.lucene.util.UnicodeUtil; import org.elasticsearch.ElasticSearchGenerationException; import org.elasticsearch.action.ActionRequestValidationException; -import org.elasticsearch.action.Actions; import org.elasticsearch.action.support.broadcast.BroadcastOperationRequest; import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; import org.elasticsearch.client.Requests; @@ -86,9 +85,6 @@ public class CountRequest extends BroadcastOperationRequest { @Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = super.validate(); - if (querySource == null) { - validationException = Actions.addValidationError("query is missing", validationException); - } return validationException; } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java index f71e9191340..c917c81df65 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java @@ -35,6 +35,7 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.FastByteArrayOutputStream; import org.elasticsearch.common.lucene.Lucene; +import org.elasticsearch.common.lucene.search.Queries; import org.elasticsearch.common.metrics.MeanMetric; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; @@ -367,7 +368,12 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I @Override public long count(float minScore, byte[] querySource, int querySourceOffset, int querySourceLength, @Nullable String[] filteringAliases, String... types) throws ElasticSearchException { readAllowed(); - Query query = queryParserService.parse(querySource, querySourceOffset, querySourceLength).query(); + Query query; + if (querySourceLength == 0) { + query = Queries.MATCH_ALL_QUERY; + } else { + query = queryParserService.parse(querySource, querySourceOffset, querySourceLength).query(); + } // wrap it in filter, cache it, and constant score it // Don't cache it, since it might be very different queries each time... // query = new ConstantScoreQuery(filterCache.cache(new QueryWrapperFilter(query))); diff --git a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/document/DocumentActionsTests.java b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/document/DocumentActionsTests.java index dd07745770e..9ac8832e935 100644 --- a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/document/DocumentActionsTests.java +++ b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/document/DocumentActionsTests.java @@ -231,6 +231,13 @@ public class DocumentActionsTests extends AbstractNodesTests { assertThat(countResponse.count(), equalTo(0l)); assertThat(countResponse.successfulShards(), equalTo(0)); assertThat(countResponse.failedShards(), equalTo(5)); + + // count with no query is a match all one + countResponse = client1.prepareCount("test").execute().actionGet(); + assertThat("Failures " + countResponse.shardFailures(), countResponse.shardFailures().size(), equalTo(0)); + assertThat(countResponse.count(), equalTo(2l)); + assertThat(countResponse.successfulShards(), equalTo(5)); + assertThat(countResponse.failedShards(), equalTo(0)); } logger.info("Delete by query");