Connection error when using a domain in python client to connect the elasticsearch

I can't connect to the es with the direct ip:9200, so I use a domain. The domain is mapping to es_ip:9200.
It's fine when I use curl command to test the connection.
curl ai-xiaov-async.vivo.com.cn/_cat/indices
But in Python, I can't connect to the es with this domain, it get a connection error.

The code in Python

from elasticsearch import Elasticsearch
class ElasticsearchViewset(viewsets.ViewSet):
    @action(methods=['GET'], detail=False, permission_classes=[AllowAny])
    def get_log(self, request):
        es = Elasticsearch(['ai-xiaov-async.vivo.com.cn'])
        result = es.info()
        return Response(result)

The error imformation

urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x00000249EF3FEE80>: Failed to establish a new connection: [WinError 10061]

elasticsearch.exceptions.ConnectionError: ConnectionError(<urllib3.connection.HTTPConnection object at 0x00000249EF3FEE80>: Failed to establish a new connection: [WinError 10061]

Can I use a domain to connect the es?

1 Like

It's sovled.
I added the port in the connection
es = Elasticsearch(['ai-xiaov-async.vivo.com.cn:80'])

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