Skip to content

Commit

Permalink
Better README examples
Browse files Browse the repository at this point in the history
  • Loading branch information
honzakral committed Jul 26, 2014
1 parent dc23b28 commit 0cdd97e
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ With the low-level client you would write something like this:
},
"filter": {"term": {"category": "search"}}
}
},
"aggs" : {
"per_tag": {
"terms": {"field": "tags"},
"aggs": {
"max_lines": {"max": {"field": "lines"}}
}
}
}
}
)
Expand All @@ -67,21 +75,15 @@ same query as:
.query("match", title="python") \
.query(~Q("match", description="beta"))
s.aggs.bucket('per_tag', 'terms', field='tags')\
.metric('max_lines', 'max', field='lines')
response = s.execute()
for hit in response:
print(hit._meta.score, hit.title)
Or, if you want to have absolute control over your queries:

.. code:: python
from elasticsearch_dsl.query import Bool, Match
s = Search(using=es).query(
Bool(
must=[Match(title="python")],
must_not=[Match(description="beta")]
)
)
for b in response.aggregations.per_tags.buckets:
print(b.key, b.max_lines.value)
The library will take care of:

Expand Down

0 comments on commit 0cdd97e

Please sign in to comment.