Yandex Cloud
Documentation
PresentationContact UsTry it for free
© 2026 Direct Cursus Technology L.L.C.
Yandex Managed Service for OpenSearch
  • Getting started
    • All guides
      • Pre-configuration
      • FQDNs of hosts
      • Connecting from applications
      • Code examples
      • Configuring SAML authentication
      • Updating a TLS certificate chain
    • User management
  • Access management
  • Inspections and recommendations
  • Pricing policy
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Public materials
  • Release notes
  • FAQ

In this article:

  • Go
  • Python
  1. Step-by-step guides
  2. Connection
  3. Code examples

Code examples for connecting to a OpenSearch cluster

Written by
Yandex Cloud
Updated at November 12, 2026
View in Markdown
  • Go
  • Python

Before connecting, prepare a certificate.

To connect, enter admin for the username and the password you set when creating the cluster.

To see code examples with the host FQDN filled in, open the cluster page in the management console and click Connect.

GoGo

Before connecting, install the required dependencies:

go mod init opensearch-example && \
go get github.com/opensearch-project/opensearch-go

Code example:

Connecting with SSL

connect.go

package main

import (
	"crypto/tls"
	"crypto/x509"
	"crypto/x509"
	"github.com/opensearch-project/opensearch-go"
	"io/ioutil"
	"log"
	"net/http"
)

var hosts = []string{
	"<FQDN_of_host_1_with_DATA_role>:9200",
	...,
	"<FQDN_of_host_N_with_DATA_role>:9200"
	}

var CA = "/home/<home_directory>/.opensearch/root.crt"

var password = "<password>"

func main() {
	caCert, err := ioutil.ReadFile(CA)
	if err != nil {
		log.Fatal(err)
	}
	caCertPool := x509.NewCertPool()
	caCertPool.AppendCertsFromPEM(caCert)

	cfg := opensearch.Config{
		Addresses: hosts,
		Transport: &http.Transport{
			TLSClientConfig: &tls.Config{
				RootCAs: caCertPool,
			},
		},
		Username: "admin",
		Password: password,
	}
	es, err := opensearch.NewClient(cfg)
	if err != nil {
		log.Printf("Error creating the client: %s", err)
	} else {
		log.Println(es.Info())
	}
}

Unlike other connection methods, in this example, you need to use the full path to the RootCA.pem certificate for OpenSearch in the CA variable.

Learn how to get a host FQDN in this guide.

Connecting:

go run connect.go

PythonPython

Before connecting, install the required dependencies:

sudo apt update && sudo apt install --yes python3 python3-pip && \
pip3 install opensearch-py

Code example:

Connecting with SSL

connect.py

from opensearchpy import OpenSearch

CA = '~/.opensearch/root.crt'
PASS = '<password>'
HOSTS = [
  "<FQDN_of_host_1_with_DATA_role>",
  ...,
  "<FQDN_of_host_N_with_DATA_role>"
]

conn = OpenSearch(
  HOSTS,
  http_auth=('admin', PASS),
  use_ssl=True,
  verify_certs=True,
  ca_certs=CA)

print(conn.info())

Learn how to get a host FQDN in this guide.

Connecting:

python3 connect.py

Was the article helpful?

Previous
Connecting from applications
Next
Configuring SAML authentication
© 2026 Direct Cursus Technology L.L.C.