I followed AWS OpenSearch tutorial to set up a very simple server with username:password authentication.
When I use their python client (opensearch-py) to connect to the server, some weird thing happened. What I followed the sample code given in the opensearch-py document.
As I don't use any certificates, I disabled those lines.
host = 'https://xyz.us-east-1.es.amazonaws.com/'
port = 443
auth = ('admin', 'adminpasswd')
client = OpenSearch(
hosts = [{'host': host, 'port': port}],
http_compress = True, # enables gzip compression for request bodies
http_auth = auth,
# client_cert = client_cert_path,
# client_key = client_key_path,
use_ssl = True,
verify_certs = False,
ssl_assert_hostname = False,
ssl_show_warn = False,
# ca_certs = ca_certs_path
)
If I use such client to do any index, I got
: [Errno 11001] getaddrinfo failed) caused by: NewConnectionError(<urllib3.conne
ction.HTTPSConnection object at 0x0000016A974399D0>: Failed to establish a new c
onnection: [Errno 11001] getaddrinfo failed)
Then, I googled some elasticsearch document, and find two ways to successfully establish to connection.
The first way is change hosts = [{'host': host, 'port': port}], in the above code to hosts = host, as the port I used is standard https port, I guess it does not matter. Another way is just simply build up a full URL by client = OpenSearch('https://admin:adminpasswd@xyz.us-east-1.es.amazonaws.com/')
The second fix is just simple, and also runs much faster. I am wondering what is wrong with the original solution given out in the opensearch official document. Do you have any suggestions for good references for opensearch APIs? It seems opensearch documents are sometimes not as early as elasticsearch documents, and I need to refer to es documents frequently.