Skip to main content

aioelasticsearch-py wrapper for asyncio

Project description

info:

aioelasticsearch-py wrapper for asyncio

https://img.shields.io/travis/wikibusiness/aioelasticsearch.svg https://img.shields.io/pypi/v/aioelasticsearch.svg

Installation

pip install aioelasticsearch

Usage

import asyncio

from aioelasticsearch import Elasticsearch

async def go():
    es = Elasticsearch()

    print(await es.search())

    await es.close()

loop = asyncio.get_event_loop()
loop.run_until_complete(go())
loop.close()

Features

Asynchronous scroll

import asyncio

from aioelasticsearch import Elasticsearch
from aioelasticsearch.helpers import Scan

async def go():
    async with Elasticsearch() as es:
        async with Scan(
            es,
            index='index',
            doc_type='doc_type',
            query={},
        ) as scan:
            print(scan.total)

            async for scroll in scan:
                for doc in scroll:
                    print(doc['_source'])

loop = asyncio.get_event_loop()
loop.run_until_complete(go())
loop.close()

Coroutine version of scroll

import asyncio

from aioelasticsearch import Elasticsearch
from aioelasticsearch.helpers import Scan

@asyncio.coroutine
def go():
    es = Elasticsearch()
    try:
        with Scan(
            es,
            index='index',
            doc_type='doc_type',
            query={},
        ) as scan:
            try:
                yield from scan.scroll()
                print(scan.total)

                for scroll in scan:
                    scroll = yield from scroll

                    for doc in scroll:
                        print(doc['_source'])
            finally:
                yield from scan.clear_scroll()
    finally:
        yield from es.close()

loop = asyncio.get_event_loop()
loop.run_until_complete(go())
loop.close()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aioelasticsearch-0.1.8.tar.gz (9.1 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page