[Yandex Cloud documentation](../../../index.md) > [Yandex Managed Service for OpenSearch](../../index.md) > [Step-by-step guides](../index.md) > [Connection](index.md) > Code examples

# Code examples for connecting to a OpenSearch cluster

Before connecting, [prepare a certificate](index.md#ssl-certificate).

To connect, enter `admin` for the username and the password you set when [creating the cluster](../cluster-create.md#create-cluster).

To see code examples with the host FQDN filled in, open the cluster page in the [management console](https://console.yandex.cloud) and click **Connect**.

## Go {#go}

Before connecting, install the required dependencies:

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

{% list tabs group=connection %}

- Connecting with SSL {#with-ssl}

    1. Code example:

       `connect.go`

        ```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.

    1. Connecting:

        ```bash
        go run connect.go
        ```

{% endlist %}

Learn how to get a host FQDN in [this guide](fqdn.md).

## Python {#python}
  
Before connecting, install the required dependencies:

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

{% list tabs group=connection %}

- Connecting with SSL {#with-ssl}

    1. Code example:

        `connect.py`

        ```python
        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())
        ```

    1. Connecting:

        ```bash
        python3 connect.py
        ```

{% endlist %}

Learn how to get a host FQDN in [this guide](fqdn.md).