Install the Low-level Python Client for Elasticsearch
- Python is a high-level general-purpose programming language that you’ll frequently need to use in Elasticsearch. Fortunately, Elastic maintains its own official git repository for the low-level Python client. The
pip3commands discussed below will be the same, regardless of the operating system you’re running. This tutorial will provide step-by-step instructions on how to install a low-level Python client in Elasticsearch.
- Python must already be installed on your system. This article assumes you’re using Python 3, as Python 2 will be depreciated by 2020. Check your version of Python with the following command:
pip3 package manager
pip3if you haven’t done so yet. You can also upgrade it with the following command:
- Consult the documention for more information on installing PIP.
Python 3 on Windows
- If you installed Python 3 on Windows,
pip3should already be packaged with it.
Python 3 on Linux
- Install Python with the
aptpackage manager if you installed Python 3 on a Debian-based version of Linux and can’t find pip3. The following command shows how to do this:
- Use the
yumpackage manager to install Python if you’re running on a Red Hat distribution Linux and can’t find
pip3. This command shows how :
Python 3 and MacOS
- Python 2 is the default version of Python on macOS. Use HomeBrew to install Python 3 on a macOS system as follows:
Install the Elasticsearch low-level client for Python
- Install the Python client Elasticsearch once Python 3 and PIP for Python 3 are installed and running.
Install the Client
- This command uses
pip3to install the Elasticsearch client :
According to the Elasticsearch github repository, the major client version number of the Python client should match the major client version number of Elasticsearch. For example, use version
5.x of the Python client if your version of Elasticsearch is
5.x. The following commands show how to check the versions of Elasticsearch and Python:
curl -XGET "http://localhost:9200/"
# get Python client version
pip3 freeze | grep elasticsearch
Import the Elasticsearch library
Python has a built-in console interpreter you can access if it’s installed on your system. Type
python3and press Return to enter this interpreter.
Once you’re in the interpreter, enter the following command to ensure that the Elasticsearch client is properly installed:
The client is installed unless Python raises an
ImportErrorafter you enter the above command.
Create a new instance of the Elasticsearch client to ensure the Python library is working properly by using the following command:
- Press CTRL + Z to exit the Python interpreter.
This tutorial showed how to install a low level Python client for Elasticsearch. It also included instructions for installing pip3, which the Python client requires. The specific steps for this procedure depend on the operating system, which include Windows, macOS and various types of Linux.