1

While testing about with ES I'm struggling to get it to work with it's Python Client. I've followed the quick-start guide and set up local Docker containers running both ES and Kibana. To test the installation I used Postman to send some requests over to http://localhost:9200/ which responded with proper data.

The Python Client however fails to connect - installed it via Pip, imported it and set it up like so:

from elasticsearch import Elasticsearch

es = Elasticsearch(
    ['localhost'],
    scheme="http",
    port=9200,
)

if not es.ping():
    raise BaseException("Connection failed")

The Error being thrown:

Failed to establish a new connection: [Errno 111] Connection refused

Here's an excerpt from my docker-compose:

es01:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.13.3
    container_name: es01
    environment:
      - node.name=es01
      - cluster.name=es-docker-cluster
      - discovery.seed_hosts=es02,es03
      - cluster.initial_master_nodes=es01,es02,es03
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - data01:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
    networks:
      - elastic

Note that my python-container does not share the network with ES - does that play a notable role here?

1 Answer 1

2

Turns out it was related to the networks.

I've fixed this issue by including ES and Kibana in the same network as my Python application and changing the initialization to:

from elasticsearch import Elasticsearch

es = Elasticsearch(
    ['es01'],
    scheme="http",
    port=9200,
)
if not es.ping():
    print("Connection failed")
else:
    print("Connection successful")

es01 references the name of the docker container running Elasticsearch.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.