# Getting error while making asynchronous call into es.search() from Flask python API

**URL:** <https://discuss.elastic.co/t/getting-error-while-making-asynchronous-call-into-es-search-from-flask-python-api/282703>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [August 27, 2021, 6:26pm UTC](https://discuss.elastic.co/t/getting-error-while-making-asynchronous-call-into-es-search-from-flask-python-api/282703 "2021-08-27T18:26:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SCode](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/scode/32/80406_2.png) [@SCode](https://discuss.elastic.co/u/SCode)\
**Post date:** [August 27, 2021, 6:26pm UTC](https://discuss.elastic.co/t/getting-error-while-making-asynchronous-call-into-es-search-from-flask-python-api/282703/1 "2021-08-27T18:26:08Z")

</div>

Error message looks like  
`Error occurred: '<' not supported between instances of 'AIOHttpConnection' and 'AIOHttpConnection'`

Also, at times it throws this error  
`Error occurred: ConnectionError(Event loop is closed) caused by: RuntimeError(Event loop is closed)`

I am using AsyncElasticsearch() with Python Flask 2.0.1

Anyone facing this issue? How to handle multiple asynchronous search REST API requests?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [August 30, 2021, 11:17am UTC](https://discuss.elastic.co/t/getting-error-while-making-asynchronous-call-into-es-search-from-flask-python-api/282703/2 "2021-08-30T11:17:00Z")

</div>

can you share some code as well, that might help to shed some light on the issue?

Thank you!

---

<div class="post-metadata">

**Author:** ![SCode](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/scode/32/80406_2.png) [@SCode](https://discuss.elastic.co/u/SCode)\
**Post date:** [August 30, 2021, 12:13pm UTC](https://discuss.elastic.co/t/getting-error-while-making-asynchronous-call-into-es-search-from-flask-python-api/282703/3 "2021-08-30T12:13:48Z")

</div>

This issue occurred when using `flask` library.  
Consider the below example:  
First time when `get_data` is invoked via API, it worked fine, return the data. On successive attempts it started failing.

```auto
from flask import Flask
from elasticsearch import AsyncElasticsearch

es = AsyncElasticsearch([
    {'host': 'localhost'}
])

async def get_data(self, index, page_from=0, page_size=5):
    body = {"query": {"match_all": {}}}
    return await self.es.search(
        index=index,
        body=body,
        from_=page_from,
        size=page_size
    )

```

Instead of using `from flask import Flask` I tried with aioFlask `from aioflask import Flask` and it worked fine.

Happy to take your suggestion as well.

Also, would like to know if async elasticsearch is compatible with flask 2.x as of now.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 27, 2021, 12:14pm UTC](https://discuss.elastic.co/t/getting-error-while-making-asynchronous-call-into-es-search-from-flask-python-api/282703/4 "2021-09-27T12:14:25Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
