rest _count endpoint to also allow for no query provided (defaults to match_all)

This commit is contained in:
Shay Banon 2011-10-14 17:53:27 +02:00
parent a76737ceaf
commit 6b497589ce
2 changed files with 5 additions and 2 deletions

View File

@ -76,7 +76,10 @@ public class RestCountAction extends BaseRestHandler {
if (source != null) { if (source != null) {
countRequest.query(source); countRequest.query(source);
} else { } else {
countRequest.query(RestActions.parseQuerySource(request)); byte[] querySource = RestActions.parseQuerySource(request);
if (querySource != null) {
countRequest.query(querySource);
}
} }
} }
countRequest.queryHint(request.param("query_hint")); countRequest.queryHint(request.param("query_hint"));

View File

@ -72,7 +72,7 @@ public class RestActions {
public static byte[] parseQuerySource(RestRequest request) { public static byte[] parseQuerySource(RestRequest request) {
String queryString = request.param("q"); String queryString = request.param("q");
if (queryString == null) { if (queryString == null) {
throw new ElasticSearchIllegalArgumentException("No query to execute, not in body, and not bounded to 'q' parameter"); return null;
} }
QueryStringQueryBuilder queryBuilder = QueryBuilders.queryString(queryString); QueryStringQueryBuilder queryBuilder = QueryBuilders.queryString(queryString);
queryBuilder.defaultField(request.param("df")); queryBuilder.defaultField(request.param("df"));