With Bonsai, customers get a robust, opinionated cluster that scales elastically to your usage. Every production Bonsai cluster is monitored 24/7, replicated for high availability, and automatically backed up hourly.
Bonsai on Heroku supports the Heroku workflow – because that’s how we work too.
Click a button, launch a cluster.
As your application grows and your needs change, no worries – we’ve got an instance for that. From hobby projects to Private spaces and everything in between, regardless of the type of instance you need, we can help. Find out how we can help you.
Ready to power your search with AI?
Launch a fully managed Elasticsearch or OpenSearch cluster, with built-in vector search and AI capabilities.
Deploying NestJS with Elasticsearch 7.10.2 on Heroku
We'll be using the NestJS application from
our "Supercharge Your NestJS App with
Hosted Search"
article, which you can grab
at https://github.com/omc/bonsai-examples/tree/main/nodejs/nestjs! In this
article, we'll be working towards parity of this application on the
nestjs/bonsai-deployed-on-heroku branch.
Once you've cloned that app, we've got just a little bit of set-up to do before we dive in!
Application house-keeping and configuration
-
First, if you cloned the source code with git, you'll need to move the NestJS application to its own directory, outside of the git tree for the
bonsai-examplesrepository: this is due to the fact that we'll be deploying with agit pushto Heroku's provided git server!# from within the bonsai-examples directory -
Initialize the
nestjssub-directory as a git repository, and add an initial commit:
Setting up our Heroku application and dependencies
-
Ensure you've got the Heroku CLI installed, and are logged in!
-
From within the application's root folder (e.g.
/home/my_user/bonsai-examples/nodejs/nestjs/), create a Heroku app:
You should see a response from the CLI that includes an app name (mine was the
intriguing, "floating-escarpment-09801"), deployment URL, and git repository
link.
With our app created, we can begin to attach dependencies. We'll start with a PostgreSQL relational database.
Follow the instructions output by the CLI application until the database is provisioned and available for use! Mine only took a couple of minutes before being available!
Next, we'll create a Bonsai Elasticsearch database.
For our use case, we'll be using the free sandbox plan, running Elasticsearch:
Similar to the previous step, we'll want to wait and monitor this addon for deployment status before moving on, so follow the instructions output by the Heroku CLI until your new Bonsai Elasticsearch cluster is available! Mine was up-and-running in just a few seconds!
Configuring our application to use the Bonsai Elasticsearch 7.10.2 Heroku addon
Next, we'll need to update our application's configuration a tiny bit to ensure
that we pick up the new BONSAI_URL environment variable from our newly
deployed Bonsai Elasticsearch cluster.
First, we'll update our src/database/config/search.config.ts to use the
BONSAI_URL environment variable. Update yours to match!
// src/database/config/search.config.ts
;
;
;
;
;
;
;
Next, as part of our deployment, we'll want to run our search database seed
script in production, so let's update the src/Procfile to look like this:
web: npm run start:prod
release: echo '' > .env && npm run migration:run && npm run seed:run:
relational && npm run seed:run:search
Save these new changes with a git commit:
And, since Heroku prunes some of our development dependencies, which we'll use
for running database migrations, we need to do a little bit of work on our
package.json. Specifically, we're going to promote a couple of packages from
devDependencies to dependencies:
-
Add this
heroku-prebuildhook under"scripts":"scripts": -
Move these dependencies from the
"devDependencies"section to"dependencies":"dependencies":
Finally, since we know that our production PostgreSQL deployment will be using
SSL (as Heroku requires it for all Heroku Postgres production databases), we can
set that and a few other relevant database settings for our production app right
on the command line (because our app is expecting them in src/database/data-source.ts).
Let's run another git commit before our final push:
Deploying with Bonsai Elasticsearch to Heroku with a git push
The moment we've all been waiting for. The pièce de résistance.
This single command will trigger the applications build pipeline, run database migrations, seed the relational database, and then seed the search database!
It all happened in under a minute for me, and now we're ready to search through our movie titles:
{
{
}
{
}
}
Next Steps for your Heroku-deployed Elasticsearch / OpenSearch cluster
Now that you're live with the Bonsai Search stack on the Heroku platform, send us an email and we'll happily work with you to understand where you are on your search journey and where you want to go. We're excited to help you take your search to the next level!
Ready to power your search with AI?
Launch a fully managed Elasticsearch or OpenSearch cluster, with built-in vector search and AI capabilities.
Learn how a managed service works and why it’s valuable to dev teams
You won’t be pressured or used in any manipulative sales tactics
We’ll get a deep understanding of your current tech stack and needs
Get the information you need to decide whether to go with Bonsai
Or, schedule a consultation: