Home > Software engineering >  How do I launch an elasticsearch instance from Python?
How do I launch an elasticsearch instance from Python?

Time:12-27

Please pardon me if I ask a silly question. I am completely new to programming in general.

I have installed ElasticSearch on Python using pip install elasticsearch. How do I instantiate an elastic search variable in python?

CodePudding user response:

No question is a silly question. Congratulations on starting with programming and programming in Python. I wish you all the best.

  1. The first thing you need to do to instantiate an ElasticSearch search using python is to make sure you have ElasticSearch downloaded onto your machine. Download it from here and follow the instructions to unpack.
  2. After the download, go to the terminal and enter the ElasticSearch directory cd elasticsearch-x.xx.x/ (for e.g., cd elasticsearch-7.16.2/) and execute .bin/elasticsearch.
  3. Once ElasticSearch is up and running, begin writing the Python script where you want to instantiate ElasticSearch instance as follows.

from elasticsearch import Elasticsearch
es = Elasticsearch( [{u'host': u'127.0.0.1', u'port': b'9200'}] )

  • Related