Can't connecte to elasticsearch using python

i have my Elasticsearch container running on my virtual machine en port 8081:9200 and i need to connect to it using python code when runnnig a script to create index in Elasticsearch

# Import packages
from elasticsearch import Elasticsearch

# Elastic search configuation
#es = Elasticsearch(HOST="http://localhost", PORT=8081)
#es = Elasticsearch()
es = Elasticsearch('http://localhost:9200')

# Creating index
es.indices.create(index="firstindex")

i got this error

my Elasticsearch container is runing well

The IP you are accesing via web browser does not match with the one you are setting up on your code "localhost". Could be that the issue?

1 Like

yees thanks

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.