Elasticsearch multiple connections using python

Hi, I am using python to connect to my Elasticsearch and execute a search query.
I have noticed that the python Elasticsearch module is making 2 connexion to the specified cluster.

is that normal ?
if not how can i correct this behaviour ?

thank in advance for your help
here is the code

try:
        #Connect to the specified Cluster
        print(str(datetime.now()) + " Tentative de connexion au cluster " + CLUSTER)
        es = Elasticsearch([CLUSTER],
            http_auth=(user, password),
            ssl_context=ssl_context
        )
        # Check cluster connection with a ping.
        # if ping Ok then the cluster connection is OK
        try :
            es.ping()
            print(str(datetime.now()) + " Connexion au cluster "+ CLUSTER +" reussi")
            return es
        except exceptions as ex:
            print("Exception : {}".format(datetime.now()))
            print(traceback.format_exc())
            exit()
    except exceptions as e:
        print("Exception : {}".format(datetime.now()))
        print(e)
        exit()

where did you see it is creating two connection?

I see it in my log every time a execute the script

2021-11-29 16:11:20.732000 Tentative de connexion au cluster https://my_cluster
2021-11-29 16:11:20.928000 Connexion au cluster https://my_cluster/ reussi
2021-11-29 16:11:20.946000 Tentative de connexion au cluster https://my_cluster/
2021-11-29 16:11:21.119000 Connexion au cluster https://my_cluster/ reussi

sorry the log is in french but it says:
"2021-11-29 16:11:20.732000 trying to connect to the cluster https://my_cluster
2021-11-29 16:11:20.928000 connection to the cluster https://my_cluster ok
2021-11-29 16:11:20.946000 trying to connect to the cluster https://my_cluster
2021-11-29 16:11:21.119000 connection to the cluster https://my_cluster ok"

it does not mean it is keeping that two connection. it might be closing and opening as needed.
though I am not internal developer of python api. I will not worry to much until it causing a problem.

it seems like first one is you creating pointer to cluster i.e es =
and second you are trying es.ping ( which might be pingining cluster and closing after that)

What is the rest of your python script? Can you share your full script to help understand why you are going into the try blocks twice?

I figured it out !

i Had another method calling the connexion Method, so I fixed it

thanks for your help

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