Skip to content

Commit

Permalink
Added aggregations to response if requested
Browse files Browse the repository at this point in the history
  • Loading branch information
snakeye committed Aug 7, 2018
1 parent 00e7490 commit 23b9dfe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
15 changes: 14 additions & 1 deletion elasticmock/fake_elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

from elasticmock.utilities import get_random_id


PY3 = sys.version_info[0] == 3
if PY3:
unicode = str
Expand Down Expand Up @@ -182,6 +181,20 @@ def search(self, index=None, doc_type=None, body=None, params=None):
hits.append(match)
result['hits']['hits'] = hits

# build aggregations
if 'aggs' in body:
aggregations = {}

for aggregation, definition in body['aggs'].items():
aggregations[aggregation] = {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": []
}

if aggregations:
result['aggregations'] = aggregations

return result

@query_params('consistency', 'parent', 'refresh', 'replication', 'routing',
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
setup(
name='ElasticMock',
version=__version__,
url='https://github.com/vrcmarcos/elasticmock',
url='https://github.com/snakeye/elasticmock',
license='MIT',
author='Marcos Cardoso',
author_email='[email protected]',
Expand All @@ -17,8 +17,8 @@
include_package_data=True,
platforms='any',
install_requires=[
'elasticsearch<=1.9.0',
'mock<=1.0.1'
'elasticsearch',
'mock'
],
classifiers=[
'Environment :: Web Environment',
Expand Down

0 comments on commit 23b9dfe

Please sign in to comment.