Connecting to Elasticsearch with Python


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


Spin up a cluster in less
than 5 minutes.
(No credit card required)

Sign Up Now

Site by Swell Design Group