Skip to content

Commit

Permalink
tiny doc typo and docs formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
honzakral committed Apr 21, 2015
1 parent 43236b0 commit 6cd01bb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/persistence.rst
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ metadata for your document:
created from the fields on the document class itself.

Any attributes on the ``Meta`` class that are instance of ``MetaField`` will be
used to control the mapping of the mata fields (``_all``, ``_parent`` etc).
used to control the mapping of the meta fields (``_all``, ``_parent`` etc).
Just name the parameter (without the leading underscore) as the field you wish
to map and pass any parameters to the ``MetaField`` class:

Expand Down
30 changes: 25 additions & 5 deletions docs/search_dsl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ Queries



The library provides classes for all Elasticsearch query types. Pass all the parameters as keyword arguments:
The library provides classes for all Elasticsearch query types. Pass all the
parameters as keyword arguments:

.. code:: python
Expand Down Expand Up @@ -201,19 +202,38 @@ To nest aggregations, you can use the ``.bucket()`` and ``.metric()`` methods:
a = A('terms', field='category')
# {'terms': {'field': 'category'}}
a.metric('clicks_per_category', 'sum', field='clicks').bucket('tags_per_category', 'terms', field='tags')
# {'terms': {'field': 'category'}, 'aggs': {'clicks_per_category': {'sum': {'field': 'clicks'}}, 'tags_per_category': {'terms': {'field': 'tags'}}}}
a.metric('clicks_per_category', 'sum', field='clicks')\
.bucket('tags_per_category', 'terms', field='tags')
# {
# 'terms': {'field': 'category'},
# 'aggs': {
# 'clicks_per_category': {'sum': {'field': 'clicks'}},
# 'tags_per_category': {'terms': {'field': 'tags'}}
# }
# }
To add aggregations to the ``Search`` object, use the ``.aggs`` property, which
acts as a top-level aggregation:
.. code:: python
s = Search()
s.aggs.bucket('per_category', 'terms', field='category').metric('clicks_per_category', 'sum', field='clicks').bucket('tags_per_category', 'terms', field='tags')
s.aggs.bucket('per_category', 'terms', field='category')\
.metric('clicks_per_category', 'sum', field='clicks')\
.bucket('tags_per_category', 'terms', field='tags')
s.to_dict()
# {'aggs': {'per_category': {'terms': {'field': 'category'}, 'aggs': {'clicks_per_category': {'sum': {'field': 'clicks'}}, 'tags_per_category': {'terms': {'field': 'tags'}}}}}}
# {
# 'aggs': {
# 'per_category': {
# 'terms': {'field': 'category'},
# 'aggs': {
# 'clicks_per_category': {'sum': {'field': 'clicks'}},
# 'tags_per_category': {'terms': {'field': 'tags'}}
# }
# }
# }
# }
You can access an existing bucket by its name:
Expand Down

0 comments on commit 6cd01bb

Please sign in to comment.