From 55d9bf8f010b9b24071eae72452c8ea069d28275 Mon Sep 17 00:00:00 2001 From: Nick Barrett Date: Sun, 7 Feb 2016 15:39:26 +0000 Subject: [PATCH] v3. --- CHANGELOG.md | 2 +- README.md | 57 ++++++++++------------------------------------------ setup.py | 2 +- 3 files changed, 13 insertions(+), 48 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 791b979..b9f2271 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# v3 (WIP) +# v3 + Full ES 2 DSL support + Removed `Filter` & ES 1 support diff --git a/README.md b/README.md index 6ce83a7..712b405 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,11 @@ -# ElasticQuery v3 (WIP) [![PyPI version](https://badge.fury.io/py/ElasticQuery.svg)](https://pypi.python.org/pypi/ElasticQuery) +# ElasticQuery v3 [![PyPI version](https://badge.fury.io/py/ElasticQuery.svg)](https://pypi.python.org/pypi/ElasticQuery) A simple query builder for Elasticsearch. Install with `pip install elasticquery`. Uses metod calls and their args/kwargs to generate query/filter/aggregate objects. Outputs dict/json represntation to be passed directly to ES. -### API - -+ [ElasticQuery](https://elasticquery.readthedocs.org/client.html) -+ [Queries](https://elasticquery.readthedocs.org/queries.html) -+ [Aggregates](https://elasticquery.readthedocs.org/aggregates.html) -+ [Suggesters](https://elasticquery.readthedocs.org/suggesters.html) -+ [Filters](https://elasticquery.readthedocs.org/filters.html) ++ [Documentation](https://elasticquery.readthedocs.org/en/latest/) ++ [Queries API](https://elasticquery.readthedocs.org/en/latest/queries.html) ++ [Aggregates API](https://elasticquery.readthedocs.org/en/latest/aggregates.html) ++ [Suggesters API](https://elasticquery.readthedocs.org/en/latest/suggesters.html) ## Synopsis @@ -18,44 +15,21 @@ from elasticsearch import Elasticsearch from elasticquery import ElasticQuery, Filter, Query +# Create a query with our ES index details q = ElasticQuery( es=Elasticsearch(), index='mapping_test', doc_type='doc_mapping' ) -# -> query.filtered.filter -q.filter( - # -> query.filtered.filter.bool - Filter.bool(must=[ - # -> query.filtered.filter.bool.must.terms - Filter.terms('field', ['this', 'that']) - ], must_not=[ - # -> query.filtered.filter.bool.must_not.or - Filter.or_( - # -> query.filtered.filter.bool.must_not.or.term - Filter.term('another_field', 'matching-term'), - # -> query.filtered.filter.bool.must_not.or.query.query_string - Filter.query( - Query.query_string('A QUERY STRING', default_operator='OR') - ) - ) - ]) -) - -# -> query.filtered.query +# Query it! q.query( - # -> query.filtered.query.prefix - Query.prefix('field', 'prefixed-') + Query.terms('my_field', ['my', 'terms']) ) -# -> aggregates +# Aggregate it! q.aggregate( - # -> aggregates.agg_name - Aggregate.date_histogram('agg_name', 'date_field', '1d').aggregate( - # aggregates.agg_name.aggregates.sub_agg_name - Aggregate.terms('sub_agg_name', 'terms_field', size=50) - ) + Aggregate.sum('my_agg', 'my_field') ) # Print the query, then run on ES and print it's output @@ -64,16 +38,7 @@ print q.get() ``` -## Naming Differences - -ElasticQuery attempts to keep all names and arguments in-line with their ES coutnerparts. Unfortunately a number of key terms are reserved by Python, so ElasticQuery implements the following alternatives: - -+ `from` -> `from_` (eg setting query['from']) -+ `or` -> `or_` (eg or_filters) -+ `and` -> `and_` (eg and_filters) - - -## Testing +## Development/Testing + Create virtualenv + `pip install requirements.pip` diff --git a/setup.py b/setup.py index 10c140a..4e1a1f7 100755 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ if __name__ == '__main__': setup( - version='3.dev0', + version='3', name='ElasticQuery', description='A simple query builder for Elasticsearch 2', author='Nick Barrett',