Search code examples
python-3.xelasticsearchasynchronoustornado

Use elasticsearch_async with tornado


I am trying to use elasticsearch_async (repo) with tornado 6.0.3.

From what I understood going through the code, if I use AsyncElasticSearch and pass the current tornado ioloop, it will work. Can someone confirm or point to an example?

My second question is - I see AsyncElasticSearch uses AIOHttpConnection (code) internally as the default connection_class. Do I need to create a new connection_class adapter to pass to the connection_class which uses tornado's AsyncHttpClient or will the tornado work seamlessly with AIOHttpConnection?


Solution

  • From what I understood going through the code, if I use AsyncElasticSearch and pass the current tornado ioloop, it will work. Can someone confirm or point to an example?

    AsyncElasticSearch wants an asyncio event loop, not a Tornado IOLoop. But in Tornado 6 the Tornado IOLoop is just a wrapper around the asyncio event loop, so if you just ignore all of this and use the defaults everything should just work.

    Do I need to create a new connection_class adapter to pass to the connection_class which uses tornado's AsyncHttpClient or will the tornado work seamlessly with AIOHttpConnection?

    No. Just let AsyncElasticSearch use aiohttp even if other parts of your application are using AsyncHTTPClient. It should all just work together (although I haven't actually tried this combination).