question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Integration of official async ES client into DSL library

See original GitHub issue

Hi team,

Great effort on contributing and maintaining a great layer on top of ES access.

While there are some discussions around the async integration into the official DSL library like #704 and #556 I did not find any conclusion on that. I did my research and also found there isn’t anything existing. While there are some prototypes and suggestions like here I did not see an implementation.

I was presuming, it could be due to two reasons: Either its really not there and no body has raised a PR yet, (or) this could be a trivial implementation so most users took care by overriding the parent classes.

In any case, I needed the integration of the official async python library into DSL. I was experimenting many ways, and something simple yet required to duplicate was to create async_xyz classes on top of the low level APIs that were accessing the es client functions and eventually not awaiting the coroutines from async ES client.

That said, here is a very basic working/and tested implementation in my fork https://github.com/elastic/elasticsearch-dsl-py/compare/master...vaidsu:master

Please consider this as a basic prototype implementation and I just started writing tests. I am not sure, if this is good to go, or not. Then if yes, need to understand how far I need to write tests, I am just planning to make all the sync tests runnable on async calls.

Please let me know. If you like the thought, but have suggestions, also feel free to share – I am open to contribute back.

Thanks

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:19 (7 by maintainers)

github_iconTop GitHub Comments

13reactions
timothycrosleycommented, Sep 3, 2019

Now that Python2 is imminently reaching EOL, would a Python3 solution be accepted? If not, what would need to be changed from @vaidsu’s solution to make it acceptable?

Thanks!

~Timothy

2reactions
braunsonmcommented, Aug 14, 2018

Thanks for the info @vaidsu

Is there a way to access the async es wrapper after initializing the DSL with create_connection? If so that would be useful as well for using the regular elasticsearch py syntax as well.

from elasticsearch_dsl.connections import connections

es = connections.create_connection(["hosts"])  # Way to create the connection with the async wrapper?
hw = HelloWorld(
        hello='foo',
        timestamp=time.time())
await hw.async_save()
await hw.async_update(hello="anotherworld", timestamp=int(time.time() * 1000))

# Async update?
await es.update(body={
    "script": {
        ...
    }
}, index='myindex', doc_type='hello_world', id=hw.meta.id)

Since there isn’t a way to run update scripts in the DSL right now there are some points where the underlying API has to be used.

Seems like your implementation idea is well thought out though and I hope it can be merged in the near future 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

elasticsearch-dsl-async - Python package - Snyk
Elasticsearch DSL is a high-level library whose aim is to help with writing and running queries against Elasticsearch. It is built on top...
Read more >
Using Asyncio with Elasticsearch
Starting in elasticsearch-py v7.8.0 for Python 3.6+ the elasticsearch package supports async/await with Asyncio and Aiohttp. You can either install aiohttp ...
Read more >
Community Contributed Clients - Elastic
Besides the officially supported Elasticsearch clients, there are a number of clients that have been contributed by the community for various languages:.
Read more >
Is there a Python ElasticSearch client that supports ...
Just came across this question. There is an official asynchronous Elasticsearch client based on asyncio:.
Read more >
Mocha - the fun, simple, flexible JavaScript test framework
js and in the browser, making asynchronous testing simple and fun. Mocha tests run serially, allowing for flexible and accurate reporting, while mapping ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found