0

集計の結果を取得するにはどうすればよいですか?

私のコードは次のとおりです。

s = Items.search() #Items is DSL class
s.aggs.bucket('SP', 'terms', item=item_name).metric('max_amt', 'max', field='amount')
res = s.execute()

これを試すと、次のエラーが発生します。

    ERROR:django.request:Internal Server Error: /items/
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 149, in get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 147, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/shipra/codeengine/items/ES/items_views.py", line 38, in sell_items
    res = s.execute()
  File "/usr/local/lib/python2.7/dist-packages/elasticsearch_dsl/search.py", line 573, in execute
    **self._params
  File "/usr/local/lib/python2.7/dist-packages/elasticsearch/client/utils.py", line 69, in _wrapped
    return func(*args, params=params, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/elasticsearch/client/__init__.py", line 530, in search
    doc_type, '_search'), params=params, body=body)
  File "/usr/local/lib/python2.7/dist-packages/elasticsearch/transport.py", line 307, in perform_request
    status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)
  File "/usr/local/lib/python2.7/dist-packages/elasticsearch/connection/http_urllib3.py", line 93, in perform_request
    self._raise_error(response.status, raw_data)
  File "/usr/local/lib/python2.7/dist-packages/elasticsearch/connection/base.py", line 105, in _raise_error
    raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
RequestError: TransportError(400, u'search_phase_execution_exception')
4

1 に答える 1

4

呼び出しsの結果への参照を再割り当てする必要はありません(つまり、変数は必要ありません)。次のようにするだけです。aggs.bucketa

s = Items.search() #Items is DSL class
s.aggs.bucket('SP', 'terms', field=item_name).metric('max_amt', 'max', field='amount')
res = s.execute()              ^
                               |
            + change this to "field" instead of "item"

# do something with the aggs
for term in response.aggregations.SP.buckets:
    print(term.key, term.max_amt.value)
于 2015-12-22T04:09:28.530 に答える