Connecting to Elasticsearch with Python

Menu

In this example, we will use Python Elasticsearch client library. 

  • Prerequisites

You need to install Python on your machine. Depending on your operating system, download and install python. Note: This sample code uses Python3.

  • Installation

Install Python Easticseaerch client package using pip

pip3 install elasticsearch

  • Connecting to cluster

# SSL client authentication using client_cert and client_key

from ssl import create_default_context

  • Indexing

  • Getting a document

Full Sample code

Replace public IP, username and password with your real setting

Need Support
Learn More

Already have an account?
Login to the Console

Experiencing difficulties on the website or console?
Status page for known incidents


Don’t have an account yet?
Sign up for a free trial

Why sign up?
To experience the ease of creating and managing clusters via the Instaclustr Console.