Просмотр исходного кода

Allow empty json object in request body in `_count` API

When the request body is missing, all documents in the target index are counted.
As mentioned in #19422, the same should happen when the request body is an empty
json object. This is also the behaviour for the `_search` endpoint and the two
APIs should behave in the same way.
Christoph Büscher 9 лет назад
Родитель
Сommit
b861ec1cc0

+ 0 - 3
core/src/main/java/org/elasticsearch/index/query/QueryParseContext.java

@@ -73,9 +73,6 @@ public class QueryParseContext implements ParseFieldMatcherSupplier {
                     }
                 }
             }
-            if (queryBuilder == null) {
-                throw new ParsingException(parser.getTokenLocation(), "Required query is missing");
-            }
             return queryBuilder;
         } catch (ParsingException e) {
             throw e;

+ 18 - 0
rest-api-spec/src/main/resources/rest-api-spec/test/count/10_basic.yaml

@@ -37,6 +37,24 @@ setup:
 
   - match: {count : 0}
 
+---
+"count with empty body":
+# empty body should default to match_all query
+  - do:
+      count:
+        index: test
+        type: test
+        body: { }
+
+  - match: {count : 1}
+
+  - do:
+      count:
+        index: test
+        type: test
+
+  - match: {count : 1}
+
 ---
 "count body without query element":
   - do: