RediSearch / redisearch-py

RediSearch python client

Home Page:https://redisearch.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Aggregations - ValueError: need at least one field

quintonparker opened this issue · comments

So I want to run a simple aggregation that SUMs a field for all the matched records like this

127.0.0.1:6379> "FT.AGGREGATE" "analytics:search" "@ts:[1585692000000 1588284000000]" "GROUPBY" "0" "REDUCE" "SUM" "1" "@clicks" "AS" "total_clicks"
1) (integer) 1
2) 1) "total_clicks"
   2) "20"

That works as expected

But when I try the following...

    queries.append(
        aggregation.AggregateRequest(
            f"@ts:[{startTs} {endTs}]"
        ).group_by([], reducers.sum('@clicks').alias('total_clicks'))
    )

I get this...

Traceback (most recent call last):
  File "/Users/quintonparker/workspace/blah/.venv/lib/python3.7/site-packages/flask/app.py", line 2464, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/quintonparker/workspace/blah/.venv/lib/python3.7/site-packages/flask/app.py", line 2450, in wsgi_app
    response = self.handle_exception(e)
  File "/Users/quintonparker/workspace/blah/.venv/lib/python3.7/site-packages/flask/app.py", line 1867, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/quintonparker/workspace/blah/.venv/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/Users/quintonparker/workspace/blah/.venv/lib/python3.7/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/quintonparker/workspace/blah/.venv/lib/python3.7/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/quintonparker/workspace/blah/.venv/lib/python3.7/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/quintonparker/workspace/blah/.venv/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/Users/quintonparker/workspace/blah/.venv/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/quintonparker/workspace/blah/.venv/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/quintonparker/workspace/blah/app.py", line 190, in analytics
    ).group_by([], reducers.count().alias('total_queries'))
  File "/Users/quintonparker/workspace/blah/.venv/lib/python3.7/site-packages/redisearch/aggregation.py", line 205, in group_by
    group = Group(fields, reducers)
  File "/Users/quintonparker/workspace/blah/.venv/lib/python3.7/site-packages/redisearch/aggregation.py", line 90, in __init__
    raise ValueError('need at least one field')