# How to Connect to OpenSearch Database Clusters OpenSearch is an open-source search and analytics suite which serves as a centralized location to manage logs forwarded from other resources, such as databases and Droplets. You can connect to DigitalOcean Managed Databases using command line tools and other third-party clients. This guide explains where to find your OpenSearch database’s connection details and how to use them to configure tools and clients. ## Retrieve Database Connection Details Using the CLI ## How to Retrieve Database Connection Details Using the DigitalOcean CLI 1. [Install `doctl`](https://docs.digitalocean.com/reference/doctl/how-to/install/index.html.md), the official DigitalOcean CLI. 2. [Create a personal access token](https://docs.digitalocean.com/reference/api/create-personal-access-token/index.html.md) and save it for use with `doctl`. 3. Use the token to grant `doctl` access to your DigitalOcean account. ```shell doctl auth init ``` 4. Finally, run `doctl databases connection`. Basic usage looks like this, but you can [read the usage docs](https://docs.digitalocean.com/reference/doctl/reference/databases/connection/index.html.md) for more details: ```shell doctl databases connection [flags] ``` The following example retrieves the connection details for a database cluster with the ID `f81d4fae-7dec-11d0-a765-00a0c91e6bf6`: ```shell doctl databases connection f81d4fae-7dec-11d0-a765-00a0c91e6bf6 ``` ## Retrieve Database Connection Details Using the API This API call retrieves the information about your database, including its connection details. The connection details are located in the returned `connection` JSON object. ## How to Retrieve Database Connection Details Using the DigitalOcean API 1. [Create a personal access token](https://docs.digitalocean.com/reference/api/create-personal-access-token/index.html.md) and save it for use with the API. 2. Send a GET request to [`https://api.digitalocean.com/v2/databases/{database_cluster_uuid}`](https://docs.digitalocean.com/reference/api/digitalocean//index.html.md#operation/databases_get_cluster). ### cURL Using cURL: ```shell curl -X GET \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \ "https://api.digitalocean.com/v2/databases/9cc10173-e9ea-4176-9dbc-a4cee4c4ff30" ``` ### Go Using [Godo](https://github.com/digitalocean/godo), the official DigitalOcean API client for Go: ```go import ( "context" "os" "github.com/digitalocean/godo" ) func main() { token := os.Getenv("DIGITALOCEAN_TOKEN") client := godo.NewFromToken(token) ctx := context.TODO() cluster, _, err := client.Databases.Get(ctx, "9cc10173-e9ea-4176-9dbc-a4cee4c4ff30") } ``` ### Python Using [PyDo](https://github.com/digitalocean/pydo), the official DigitalOcean API client for Python: ```python import os from pydo import Client client = Client(token=os.environ.get("DIGITALOCEAN_TOKEN")) get_resp = client.databases.get_cluster(database_cluster_uuid="a7a89a") ``` ## View OpenSearch Cluster Connection Details You use your database’s connection details to configure tools, applications, and resources that connect to the database. To view your database’s connection details, click the name of the cluster on [the Databases page](https://cloud.digitalocean.com/databases) to go to its **Overview** page. ![Databases Overview screen showing connection string](https://docs.digitalocean.com/screenshots/databases/connection-details.b18206f6861c63d5a396b1c98934b93c5588ce48c46b27582d6f20337d848ccd.png) You can view customized connection details based on how you want to connect to the database: - **Public network** and **Private network** ([VPC](https://docs.digitalocean.com/products/networking/vpc/index.html.md)) options generate connection details based on if you want to connect via the cluster’s public hostname or the cluster’s private hostname. Only other resources in the same VPC network as the cluster can access it using its private hostname. - The **User** field updates the connection details with the [user credentials](https://docs.digitalocean.com/products/databases/opensearch/how-to/manage-users/index.html.md) that you would like to connect with. You can also choose to view the connection details in different formats: - **Connection parameters:** Host, port, and authentication information for application configuration. - **Connection string:** A condensed URL that you can pass to a client or use with `curl`. OpenSearch exposes a REST API over HTTPS. Use the connection details to build requests to your cluster’s endpoint (for example, `https://:25060`). By default, the control panel doesn’t reveal the cluster’s password for security reasons. Click **Copy** to copy connection details with the password, or click **show-password** to reveal the password. ## Download the SSL Certificate Each managed database comes with an SSL certificate. You can use this SSL certificate to encrypt connections between your client applications and the database. To download your database’s SSL certificate, click the name of the cluster on [the Databases page](https://cloud.digitalocean.com/databases) to go to its **Overview** page. In the **Connection Details** section, click **Download CA certificate**. ![Databases connection details with Download CA Certificate selected](https://docs.digitalocean.com/screenshots/databases/dbaas-ssl-certificate.8b2c955e8e43aa8e36b56bc98564bd42da5a9ba716eff506e1c174ca2d678d47.png) When you configure your client applications, you can use the certificate’s location on your local system. Each client application is configured differently, so check the documentation for the tool you’re using for more detail on setting up SSL connections. ## Connect to the Database You can connect to OpenSearch using the command line (for example, `curl`) or a client that supports the OpenSearch or Elasticsearch API. In this guide, we show you how to connect using `curl` and how to find connection information for applications. ## Connect Using curl To connect to OpenSearch database clusters using `curl`, you need three things: - To add your local computer [to the database’s trusted sources](https://docs.digitalocean.com/products/databases/opensearch/how-to/secure/index.html.md#firewalls). - To have `curl` installed on your local computer (it is preinstalled on most systems). - To reference the [database cluster’s connection details](https://docs.digitalocean.com/products/databases/opensearch/how-to/connect/index.html.md#connection-details), which tell your client how to connect to the cluster. To send a request to the cluster, use the hostname and port from the control panel with HTTP basic authentication. For example, to check cluster health: ```shell curl -u doadmin: \ --cacert /path/to/ca-certificate.crt \ https://:25060/_cluster/health?pretty ``` Replace `` with your database user password, `` with the hostname from the control panel, and `/path/to/ca-certificate.crt` with the path to [your database’s SSL certificate](https://docs.digitalocean.com/products/databases/opensearch/how-to/connect/index.html.md#download-the-ssl-certificate). When the connection succeeds, the cluster returns a JSON response with health and status information. From here, you can run other OpenSearch API requests. Learn more in the [OpenSearch API documentation](https://opensearch.org/docs/latest/api-reference/index-apis/index-data/). If you’re having trouble connecting to the database, you can [troubleshoot the connection using our Support page](https://docs.digitalocean.com/support/opensearch/index.html.md), or you can reference the [OpenSearch documentation](https://opensearch.org/docs/latest/). ## Connect from Applications To connect to OpenSearch database clusters from an application, you need three things: - To add the application’s host or network [to the database’s trusted sources](https://docs.digitalocean.com/products/databases/opensearch/how-to/secure/index.html.md#firewalls). - A client or library that supports the OpenSearch or Elasticsearch REST API and HTTPS with SSL/TLS (for example, the [OpenSearch client libraries](https://opensearch.org/docs/latest/clients/index/) or [Elasticsearch clients](https://www.elastic.co/guide/en/elasticsearch/client/index.html)). - To reference the [database cluster’s connection details](https://docs.digitalocean.com/products/databases/opensearch/how-to/connect/index.html.md#connection-details), which tell your client how to connect to the cluster. Configure your client with the cluster endpoint URL (for example, `https://:25060`), the database user and password from the control panel, and the path to [your database’s SSL certificate](https://docs.digitalocean.com/products/databases/opensearch/how-to/connect/index.html.md#download-the-ssl-certificate) for certificate verification. Exact configuration options depend on the client or library you use. If you’re having trouble connecting to the database, you can [troubleshoot the connection using our Support page](https://docs.digitalocean.com/support/opensearch/index.html.md), or you can reference the [OpenSearch documentation](https://opensearch.org/docs/latest/).