Using AsyncElasticsearch
Python is not a language that's famous for its performance due to the Global Interpreter Lock (GIL – https://realpython.com/python-gil/). To speed up a program that is using I/O, a new module must be created called asyncio
(https://docs.python.org/3/library/asyncio.html) that allows you to write concurrent code using the async
/await
syntax. This is the modern approach to writing Python applications and many frameworks are using it by default, such as Flask (https://flask-aiohttp.readthedocs.io/en/latest/), FastAPI (https://fastapi.tiangolo.com/), and Starlette (https://www.starlette.io/).
The Elasticsearch Python client (version 7.9.x or above) allows you to write concurrent code that uses asyncio
.
Getting ready
You will need an up and running Elasticsearch installation, as we described in the Downloading and installing Elasticsearch recipe in Chapter 1, Getting Started.
The code for this recipe can be found in the ch15/fastapi-es
directory...