Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

count doesn't work for empty query (discrepancy with search API), clo…

…ses #1377.
  • Loading branch information...
commit 4bbe1b111af4adef6482258bd33744d22ae471d0 1 parent 768c6d2
@kimchy kimchy authored
View
4 modules/elasticsearch/src/main/java/org/elasticsearch/action/count/CountRequest.java
@@ -22,7 +22,6 @@
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 CountRequest(String... indices) {
@Override public ActionRequestValidationException validate() {
ActionRequestValidationException validationException = super.validate();
- if (querySource == null) {
- validationException = Actions.addValidationError("query is missing", validationException);
- }
return validationException;
}
View
8 modules/elasticsearch/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java
@@ -35,6 +35,7 @@
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 InternalIndexShard start(String reason) throws IndexShardStartedException
@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)));
View
7 ...les/test/integration/src/test/java/org/elasticsearch/test/integration/document/DocumentActionsTests.java
@@ -231,6 +231,13 @@ protected Client getClient2() {
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");
Please sign in to comment.
Something went wrong with that request. Please try again.