diff --git a/eland/operations.py b/eland/operations.py index 68108df2..dcb5a767 100644 --- a/eland/operations.py +++ b/eland/operations.py @@ -166,8 +166,11 @@ def count(self, query_compiler: "QueryCompiler") -> pd.Series: body = Query(query_params.query) body.exists(field, must=True) + count_body = body.to_count_body() + if count_body is None: + raise ValueError("Invalid count query") field_exists_count = query_compiler._client.count( - index=query_compiler._index_pattern, **body.to_count_body() + index=query_compiler._index_pattern, **count_body )["count"] counts[field] = field_exists_count @@ -1350,8 +1353,11 @@ def index_count(self, query_compiler: "QueryCompiler", field: str) -> int: body = Query(query_params.query) body.exists(field, must=True) + count_body = body.to_count_body() + if count_body is None: + raise ValueError("Invalid count query") count: int = query_compiler._client.count( - index=query_compiler._index_pattern, **body.to_count_body() + index=query_compiler._index_pattern, **count_body )["count"] return count @@ -1388,8 +1394,11 @@ def index_matches_count( else: body.terms(field, items, must=True) + count_body = body.to_count_body() + if count_body is None: + raise ValueError("Invalid count query") count: int = query_compiler._client.count( - index=query_compiler._index_pattern, **body.to_count_body() + index=query_compiler._index_pattern, **count_body )["count"] return count