Goal
Give your app full-text search with a single-node Elasticsearch you run yourself.Prerequisites
- An application, or a name for a new one
- A size with at least 1 GB of memory; 2 GB is recommended
Workflow
1
Open Templates › Elasticsearch and choose Set up Elasticsearch. You can also create it from Databases › New database by picking the Elasticsearch engine, or from a project’s page with Add › Database › Add Elasticsearch.
2
Pick where it goes (an existing application, a new one, or next to one of your projects) and a size. 2 GB is recommended; 1 GB is for development.
3
Choose Set up Elasticsearch. The elasticsearch service starts with 10 GB of storage and a generated password for the elastic user.
4
On the canvas, open elasticsearch and choose Link an app. Pick your app and save; redeploy the app.
5
In your app, connect with ELASTICSEARCH_URL.
What you get
- Elasticsearch 9.5.6 from Elastic’s official image, as a single node, with security on and plain HTTP on port 9200 inside the private network.
- The elastic user with a 32-character password generated once and stored as the secret variable ELASTIC_PASSWORD.
- 10 GB of storage at /data that survives restarts and redeploys.
- No public address. Elasticsearch is reachable only from services in the same application.
- Elasticsearch is distributed by Elastic under the Elastic License 2.0.
From the Databases page
- New database has Elasticsearch as one of its engines. It is not a managed database: you run it, and upgrades, tuning and backups are yours.
- Pick Elasticsearch, give it a name and a size, and choose Create Elasticsearch. It is created on its own, like any database, with a generated password for the elastic user. Then you go to its page.
- Connect a project is optional: pick one of your projects that is not in an application, and choose whether to redeploy it now. The project runs next to Elasticsearch on one private network and gets ELASTICSEARCH_URL, ELASTICSEARCH_USERNAME and ELASTICSEARCH_PASSWORD.
- Connect a project later from Elasticsearch’s page or its row on the Databases page, which show Connected project with its name or Not connected. Disconnect asks first; Elasticsearch keeps running with its data.
- Elasticsearch services are listed on the Databases page under Self-hosted from templates, with their status, size, where they run and the project they are connected to. Open one to go to its page.
- Managed OpenSearch is unchanged: pick OpenSearch under New database for a search engine StackShift runs and backs up for you.
Memory
Elasticsearch sizes its memory from the service’s size. 2 GB is recommended for real traffic. 1 GB starts and works for development, but searches slow down and the node can stop when it runs out of memory. Sizes below 1 GB are refused. Resize the service from its settings when your index grows.Connect an app
Link your app to elasticsearch from the canvas. The app gets ELASTICSEARCH_URL (http://elastic:<password>@<private address>:9200), ELASTICSEARCH_USERNAME and ELASTICSEARCH_PASSWORD. Most clients need only the URL. With Node.js, install @elastic/elasticsearch:Back it up with snapshots
Backups are yours. Elasticsearch writes snapshots to a bucket through its snapshot API; the data volume alone is not a backup. Use any S3-compatible bucket, such as a StackShift bucket.- Set the bucket keys in the elasticsearch service’s variables: SNAPSHOT_S3_ACCESS_KEY and SNAPSHOT_S3_SECRET_KEY (both secret). For a bucket outside AWS, such as a StackShift bucket, also set SNAPSHOT_S3_ENDPOINT to the bucket’s S3 address. Redeploy the service; it loads the keys on every start, so they survive redeploys.
- Register the bucket as a repository, take a snapshot, and add a policy so it happens every night.
- To restore, close or delete the indices you are restoring, then call _restore with the snapshot name.
Upgrades and settings
You choose when to upgrade. Take a snapshot first. Other Elasticsearch settings go on the start command as -E<setting>=<value>.Expected result
Your app talks to Elasticsearch over the application’s private network. Nothing outside the application can reach it.
Related guides
What templates are
A template adds ready-made services, such as Elasticsearch, Grafana or Ghost, to one of your applications, next to your own apps and on the same private network.
Generated secrets, reference variables and links
How template services get their passwords, how a variable can point at another service, and what your app receives when you link it.
Terminal workspace overview
The per-project operations workspace where you open application and database shells, run runbooks and commands, and review session history and recordings.