Yandex Cloud
Search
Contact UsTry it for free
  • Customer Stories
  • Documentation
  • Blog
  • All Services
  • System Status
  • Marketplace
    • Featured
    • Infrastructure & Network
    • Data Platform
    • AI for business
    • Security
    • DevOps tools
    • Serverless
    • Monitoring & Resources
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Center for Technologies and Society
    • Yandex Cloud Partner program
    • Price calculator
    • Pricing plans
  • Customer Stories
  • Documentation
  • Blog
© 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
    • Managing users
  • Access management
  • 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 March 5, 2026
  • 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
Connecting with SSL
  1. Code example:

    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 CA.pem certificate for OpenSearch in the CA variable.

  2. Connecting:

    go run connect.go
    

To learn how to get a host FQDN, see this guide.

PythonPython

Before connecting, install the required dependencies:

sudo apt update && sudo apt install --yes python3 python3-pip && \
pip3 install opensearch-py
Connecting with SSL
  1. Code example:

    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())
    
  2. Connecting:

    python3 connect.py
    

To learn how to get a host FQDN, see this guide.

Was the article helpful?

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