/ElasticQuery

A simple (Python) query builder for Elasticsearch

Primary LanguagePythonMIT LicenseMIT

ElasticQuery v3 PyPI version

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 representation to be passed directly to ES.

Synopsis

from elasticsearch import Elasticsearch
from elasticquery import ElasticQuery, Filter, Aggregate


# Create a query with our ES index details
q = ElasticQuery(
    es=Elasticsearch(),
    index='mapping_test',
    doc_type='doc_mapping'
)

# Query it!
q.query(
    Query.terms('my_field', ['my', 'terms'])
)

# Aggregate it!
q.aggregate(
    Aggregate.sum('my_agg', 'my_field')
)

# Print the query, then run on ES and print it's output
print q.json(indent=4)
print q.get()

Development/Testing

  • Create virtualenv
  • pip install -r requirements.pip
  • Run nosetests