/elastictornado

Asynchronous ElasticSearch client via the Tornado framework for Python

Primary LanguagePythonMIT LicenseMIT

elastictornado

This Python package provides an asynchronous ElasticSearch client via the Tornado framework. Our implementation closely follows that of pyelasticsearch. As a result, the elastictornado package differs from tornado-es and other Tornado-based ES client packages because we provide a fully-featured client API along with thorough documentation, which is lacking in other packages.

Asynchronous request support has been added for methods which require the use of asynchronous libraries (like Tornado's AsyncHTTPClient library.)

Example Usage

Connection to ElasticSearch database:

from elastictornado import ElasticTornado
et = ElasticTornado('http://localhost:9200/')

Index a document:

doc = {'name': 'William Adama', 'title': 'Admiral', 'nickname': 'Husker',
       'colony': 'Caprica', 'is_cylon': False}
et.index(index='contacts', doc_type='person', doc, id=1)

Index multiple documents using the bulk-indexing API:

docs = [{'name': 'Kara Thrace', 'title': 'Captain', 'nickname': 'Starbuck',
         'colony': 'Caprica', 'is_cylon': False, 'id': 2},
        {'name': 'Sharon Valerii', 'title': 'Lieutenant', 'nickname': 'Boomer',
         'colony': 'Troy', 'is_cylon': True, 'id': 3}]

et.bulk((et.index_op(doc, id=doc.pop('id')) for doc in docs),
        index='contacts',
        doc_type='person')

Refresh the index:

et.refresh('contacts')
# {u'ok': True, u'_shards': {u'successful': 5, u'failed': 0, u'total': 10}}

Get Starbuck's document:

et.get('contacts', 'person', 2)

Perform a simple search:

et.search('nickname:Starbuck OR nickname:Boomer', index='contacts')

Perform a search using the ElasticSearch DSL:

query = {
    'query': {
        'filtered': {
            'query': {
                'query_string': {'query': 'colony:Caprica'}
            },
        },
    },
}
et.search(query, index='contacts')

Delete the index:

et.delete_index('contacts')

Installation

You can install the stable version from PyPI via:

pip install elastictornado

Alternatively, you can download the source from the GitHub repository and manually install it like so:

git clone git@github.com:ramhiser/elastictornado.git
cd elastictornado
python setup.py install

License

The elastictornado package is licensed under the MIT License. Please consult the licensing terms for more details.