> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stackshift.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenSearch

> OpenSearch 3 with its full memory reserved, hourly backups, scoped access keys and one private URL, connected to your app through OPENSEARCH_URL.

> [!TIP]
>
> **Live.** This area is documented as current, user-reliable behavior.

## Goal

Create an OpenSearch database, connect your app with an OpenSearch client, then manage indices, run requests, hand out access keys and bring in data from Elasticsearch or another OpenSearch.

## Prerequisites

* A StackShift account
* The OpenSearch client for your language, or `curl`

## Workflow

**Step 1**

Open New, then Database, then OpenSearch. You can start this from the databases page or from the project canvas add menu.

**Step 2**

Choose version 3, then pick a size. 2 GB is selected for you; 1 GB is meant for development.

**Step 3**

Choose where it runs: StackShift servers, billed by size, or one of your own servers, with no size charge.

**Step 4**

On StackShift servers, choose monthly, yearly or hourly billing and pay the first period. The database is set up as soon as the payment clears.

**Step 5**

Link the database to your app so `OPENSEARCH_URL` is set for you, then redeploy the app.

## What's included

* Full-text search with relevance scoring, highlighting and suggestions.
* Aggregations for facets, counts and analytics over your documents.
* Vector search with k-NN, for semantic search and recommendations.
* Hourly backups with restore into the same or a new database.
* ICU analysis for language-aware text handling and phonetic analysis for sounds-like matching. Other plugins can't be added.

## Compatibility

* Use the OpenSearch clients: `@opensearch-project/opensearch` for Node.js, `opensearch-py` for Python and `opensearch-go` for Go.
* Code written for Elasticsearch 7.x clients works too. Apps also get `ELASTICSEARCH_URL`, set to the same address, for that code.
* Elasticsearch 8 and newer clients refuse to connect to OpenSearch. Switch that code to the OpenSearch client for your language.
* If you need Elastic's own Elasticsearch, deploy the Elasticsearch template from Templates in the dashboard into your project. It runs as part of your project, not as a managed database.

## Sizes and prices

Each database is its own OpenSearch with its full memory reserved. It never shares that memory with other databases.

* 1 GB: ₦6,000 or \$4.62 a month. For development.
* 2 GB: ₦10,000 or \$7.69 a month.
* 4 GB: ₦16,000 or \$12.31 a month.
* 8 GB: ₦38,000 or \$29.23 a month.
* 16 GB: ₦75,000 or \$57.69 a month.
* 32 GB: ₦150,000 or \$115.38 a month.
* Storage is 10 to 1024 GB. Storage and backups are billed per GB a month. See [https://stackshift.cloud/pricing](https://stackshift.cloud/pricing).
* Pay monthly, yearly or hourly. On your own servers there is no size charge.

## Connection URL

Linking the database to an app sets `OPENSEARCH_URL`, `OPENSEARCH_USERNAME`, `OPENSEARCH_PASSWORD` and `OPENSEARCH_CA_CERT`, plus `ELASTICSEARCH_URL` with the same address for Elasticsearch 7.x clients.

The URL has this shape: `https://app:<password>@db-<id>.stackshift.internal:<port>`. The port is 9200 unless the database page shows another one.

`OPENSEARCH_CA_CERT` is `/stackshift/secrets/opensearch-ca.pem`, the CA file inside your app. To connect from anywhere else, download the CA from Connect on the database page.

Connections use HTTPS only and always need a user name and password. Point your client at the CA file so it checks the certificate.

```bash Check the connection theme={null}
curl --cacert "$OPENSEARCH_CA_CERT" "$OPENSEARCH_URL/_cluster/health?pretty"
```

## Connect from your code

Use the OpenSearch client for your language. No code changes are needed beyond reading the variables.

```javascript Node.js theme={null}
import { readFileSync } from "node:fs";
import { Client } from "@opensearch-project/opensearch";

const client = new Client({
  node: process.env.OPENSEARCH_URL,
  ssl: { ca: readFileSync(process.env.OPENSEARCH_CA_CERT) },
});

await client.index({ index: "products", body: { name: "Ada" } });
const result = await client.search({
  index: "products",
  body: { query: { match: { name: "Ada" } } },
});
```

```python Python theme={null}
import os
from opensearchpy import OpenSearch

client = OpenSearch(
    hosts=[os.environ["OPENSEARCH_URL"]],
    use_ssl=True,
    verify_certs=True,
    ca_certs=os.environ["OPENSEARCH_CA_CERT"],
)

client.index(index="products", body={"name": "Ada"})
result = client.search(index="products", body={"query": {"match": {"name": "Ada"}}})
```

```go Go theme={null}
import (
	"context"
	"crypto/tls"
	"crypto/x509"
	"log"
	"net/http"
	"os"
	"strings"

	"github.com/opensearch-project/opensearch-go/v4"
	"github.com/opensearch-project/opensearch-go/v4/opensearchapi"
)

ctx := context.Background()
ca, err := os.ReadFile(os.Getenv("OPENSEARCH_CA_CERT"))
if err != nil {
	log.Fatal(err)
}
pool := x509.NewCertPool()
pool.AppendCertsFromPEM(ca)
client, err := opensearchapi.NewClient(opensearchapi.Config{
	Client: opensearch.Config{
		Addresses: []string{os.Getenv("OPENSEARCH_URL")},
		Username:  os.Getenv("OPENSEARCH_USERNAME"),
		Password:  os.Getenv("OPENSEARCH_PASSWORD"),
		Transport: &http.Transport{TLSClientConfig: &tls.Config{RootCAs: pool}},
	},
})
if err != nil {
	log.Fatal(err)
}
_, err = client.Index(ctx, opensearchapi.IndexReq{
	Index: "products",
	Body:  strings.NewReader(`{"name":"Ada"}`),
})
```

```javascript Elasticsearch 7.x client theme={null}
import { readFileSync } from "node:fs";
import { Client } from "@elastic/elasticsearch";

const client = new Client({
  node: process.env.ELASTICSEARCH_URL,
  ssl: { ca: readFileSync(process.env.OPENSEARCH_CA_CERT) },
});

const result = await client.search({ index: "products", body: { query: { match: { name: "Ada" } } } });
```

## Indices and console

* Open Data, then Indices. Each index shows its name, status, number of documents and size.
* To delete an index, select Delete and type the index name to confirm. Its documents are gone once it is deleted.
* Open Data, then Console to send a request: pick the method, type the path such as `/products/_search`, add a JSON body and select Run. The response shows beside it.
* Reads run straight away: searches, counts, mappings, index settings, `_cat` lists and cluster health.
* Anything that changes data, such as indexing documents, creating or deleting an index or changing a mapping, asks you to confirm first. Changes that need an owner's approval wait for it.
* The console doesn't send requests to the security, snapshot, cluster settings or node APIs. StackShift looks after those so your backups and access stay safe. Use access keys to give out access.

## Access keys

* Open Settings, then Access keys, and select Create key.
* Give it a name, the index patterns it can use, such as `products` or `logs-*`, and choose Search only or Search and change.
* Search only can search and read documents. Search and change can also add, change and delete documents and create indices that match its patterns.
* Each key is its own user name and password, used with HTTPS basic sign-in like any OpenSearch user. The password is shown once, with a ready connection URL to copy.
* Add an expiry in days if the key should stop working on its own. An expired key stops working within a minute. Leave it empty to keep the key until you revoke it.
* Revoke a key from the list to stop it straight away.
* For example, a website's search box can use a Search only key limited to `products`, so it can search your catalogue but can't change it or see your other indices.

## Public access

The private address `db-<id>.stackshift.internal` is reachable only from your apps. To connect from your laptop, turn on public access in the database Settings, then use the connection URL it shows with the CA from Connect.

## Backups

* OpenSearch databases are backed up every hour. StackShift keeps 24 hourly, 7 daily and 4 weekly backups.
* Only data that changed since the last backup is uploaded, so large indices back up quickly.
* Select Back up now on the Backups tab before a risky change.
* Restore a backup into this database or into another OpenSearch database you created. Restoring in place makes the restored indices unavailable until the restore finishes. Restoring to another database leaves this one running unchanged.
* Restores go back to a backup, not to an exact second.

## Change size and storage

* Open Settings, then Size. Pick a bigger size, more storage, or both. Smaller sizes aren't offered.
* On StackShift servers you see what you pay today for the rest of the period, and the new monthly price, before anything changes.
* Changing size restarts OpenSearch in place on the same server, so searches pause for a short while. Your indices and documents stay as they are.

## Moving to another server

* Open Settings, then Move to another server. On StackShift servers, StackShift picks a server with room. On your own servers, pick which one.
* Searches keep running the whole time. Writes pause briefly at the end while the final changes are copied across.
* The address and connection URL stay the same, so your apps don't need any change.
* Back up now and restores wait until a move finishes.
* If a server is lost, StackShift recreates the database on another server from the latest backup automatically. Backups run every hour, so up to an hour of writes can be lost. Back up now shortens that.

## Import from Elasticsearch or OpenSearch

* Copy data from Elasticsearch 7.x to 9.x or OpenSearch 1.x to 3.x, from any server you can reach over HTTPS.
* Open Import and export on the database and give the old server's address as `https://user:password@host:port`. For an Elasticsearch server you can give its address with an API key instead.
* StackShift copies each index's settings, mappings and documents. The server you copy from keeps running and doesn't change.
* When the copy finishes, it shows the document count of each index on the old server and in this one, side by side.

## How it runs

* Each database is a single node. Half of its memory goes to the heap, up to 31 GB, and the rest to the file cache OpenSearch uses for fast searches.
* New indices keep OpenSearch's default of one replica. With one node that replica stays unassigned, so `_cluster/health` reports `yellow`. That is expected. StackShift counts the database as healthy when all primary shards are active.
* OpenSearch stops placing new shards when the disk is 85 to 90% full and makes indices read-only at 95%. StackShift alerts you earlier, at 75% and 85%, so you can grow storage from Settings. Once usage drops, the read-only block lifts by itself.

## Limits

* Version 3 is the only version offered.
* Each database runs on one server.
* If its server is lost, the database is recreated on another server from the latest hourly backup, so up to an hour of writes can be lost. Back up now shortens that.
* Resizing restarts OpenSearch in place on the same server.
* OpenSearch databases have no standby, restore to any second, branches, sleep or shell.

## Expected result

> [!TIP]
>
> Your app connects over HTTPS with an OpenSearch client, and searches return your documents.

## Common failures

> [!WARNING]
>
> * Certificate errors: use `https://` and point your client at the CA file in `OPENSEARCH_CA_CERT`, or the CA downloaded from Connect.
> * Connection timeout from outside StackShift: the private address only accepts connections from your apps. Turn on public access in Settings and use the public connection URL.
> * An Elasticsearch 8 or newer client won't connect: those clients only talk to Elastic's own server. Use the OpenSearch client for your language.
> * `401`: the user name or password is wrong, or the access key was revoked or has expired.
> * `403` with an access key: the index isn't in the key's index patterns, or the key is Search only and the request changes data. Create a key with the access you need.
> * `cluster_block_exception` on writes: the disk is 95% full and indices are read-only. Grow storage in Settings; writes resume on their own.
> * Cluster health is `yellow`: one replica per index can't be placed on a single node. Your data is safe and searches work.

## Related guides

> [card] [Create a database](https://docs.stackshift.cloud/databases/create-a-database.md)
>
> Create a hosted or connected-node database with private, direct public, or StackShift tunnel access.

> [card] [Database connections and tunneling](https://docs.stackshift.cloud/databases/credentials-pooling-and-usage.md)
>
> Use private, direct public, or StackShift tunnel endpoints with TLS and explicit client IP policy.

> [card] [Back up and restore a database](https://docs.stackshift.cloud/databases/back-up-and-restore-a-database.md)
>
> Use durable recovery storage correctly and understand why backups are independent from portable SQL transfers.

> [card] [Set up a template in your application](https://docs.stackshift.cloud/templates/deploy-from-a-template.md)
>
> Choose where it goes (an existing application, a new one, or next to one of your projects), where it runs, the size of each service and its public address, check what will run, then set it up.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.