Yandex Cloud
Search
Discuss with expertTry it for free
  • Customer Stories
  • Documentation
  • Blog
  • All Services
    • Cloud Interconnect
    • Cloud Backup
    • Cloud Registry
    • Yandex AI Studio
    • Compute Cloud
    • Object Storage
    • Managed Service for Kubernetes®
    • Yandex BareMetal
    • Smart Web Security
    • Security Deck
    • Managed Service for PostgreSQL
    • Managed Service for ClickHouse®
    • Monium
    • Cloud CDN
    • Network Load Balancer
    • Virtual Private Cloud
    • Cloud DNS
    • Application Load Balancer
    • Yandex Cloud Video
    • Stackland
    • Yandex Cloud Router
    • Yandex Managed Service for Trino
    • Managed Service for MySQL®
    • Managed Service for Valkey™
    • Managed Service for Apache Spark™
    • Yandex StoreDoc
    • Managed Service for OpenSearch
    • Managed Service for Apache Kafka®
    • Data Transfer
    • Yandex MPP Analytics Engine for PostgreSQL
    • Yandex Managed Service for Apache Airflow®
    • Data Processing
    • Yandex MetaData Hub
    • Managed Service for YDB
    • Managed Service for Sharded PostgreSQL
    • Managed Service for YTsaurus
    • Yandex WebSQL
    • DataLens
    • Yandex Search API
    • SpeechSense
    • SpeechKit
    • DataSphere
    • Vision OCR
    • Translate
    • Yandex Identity Hub
    • Key Management Service
    • Certificate Manager
    • Yandex Lockbox
    • Audit Trails
    • SmartCaptcha
    • Cloud Desktop
    • SourceCraft Code Assistant
    • Container Registry
    • Managed Service for GitLab
    • Managed Service for Prometheus®
    • Cloud Functions
    • API Gateway
    • Yandex Cloud Postbox
    • Message Queue
    • Serverless Integrations
    • IoT Core
    • Data Streams
    • Serverless Containers
    • Cloud Notification Service
    • Yandex Query
    • Identity and Access Management
    • Yandex Cloud Console
    • Resource Manager
    • Yandex Cloud Billing
    • Yandex Cloud Quota Manager
    • Cloud Apps
  • 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 July 6, 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
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
    

Learn how to get a host FQDN in 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
    

Learn how to get a host FQDN in this guide.

Was the article helpful?

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