Connection error caused by: ConnectionError(Connection error caused by: NameResolutionError(<elastic_transport._node._urllib3_chain_certs.HTTPSConnection object at 0x0000026D04448ED0>: Failed to resolve <url> ([Errno 11002] getaddrinfo failed)))

I am getting the above error intermittently. Below is how I am connecting with Elasticsearch. can anyone help in this

es = Elasticsearch(cloud_id=<ELASTIC_CLOUD_ID>),
                           api_key=<ELASTIC_API_KEY>)

getaddrinfo failed implies a DNS problem.

Is the machine you're running this code from connected to the internet with working DNS?

Yes. It is.
So this issue doesn't come always. Many a times, connection is successful.
But this error does come often