Some of the methods like a bulk , update have invoked from Elasticsearch. In the notion of abstraction, we could use an interface to let search service using the reference to the interface with method calls. This could be similar to the other implementation in the application. We can have a look at figure 2.1 above that the search service is implemented as a module in NestJS. Search service will inherit the attributes of Elasticsearch to take its method.
Connecting to our cluster
To enable us write our code effectively, we need data loaded into our elasticsearch. We will be using a sample dataset from Kaggle (Download it here. In this article, we will be writing the NodeJS code that will connect and query elasticsearch. Once you finish the Getting Started guide, you can start building Elasticsearch request objects. The next step, we are going to configure the Elasticsearch service in docker container rely on the docker-compose have configured. Declare search service into the provider section of the product module.
- We will be using a sample dataset from Kaggle (Download it here.
- In theory, we might use Elasticsearch as a general-purpose database.
- It offers a full-text search engine with a multitenant capability, an HTTP web interface, and schema-free JSON documents, all with simple installation.
- After executing the above command successfully, we can now connect to our elasticsearch cluster and perform CRUD operations.
- To use Elasticsearch within our NestJS project, we can use the official @nestjs/elasticsearch library.
Adding elasticsearch to your app
NestJS is a progressive Node.js web framework built with TypeScript and uses ExpressJS under the hood. We’ll be needing a few dependencies, so let’s go ahead and install them. To use Elasticsearch with Nest.js, you will need to install the @nestjs/elasticsearch package. This package provides a simple way to connect to an Elasticsearch cluster and provides the necessary components for interacting nestjs developer with the cluster. After executing the above command successfully, we can now connect to our elasticsearch cluster and perform CRUD operations.
let’s start
Docker is a tool designed to make it easy to create, deploy and run application by using containers. We’re a place where coders share, stay up-to-date and grow their careers. DEV Community — A constructive Line code and inclusive social network for software developers. Thank you to our Diamond Sponsor Neon for supporting our community. It will become hidden in your post, but will still be visible via the comment’s permalink. The current version (2.x) is fully compatible with Elasticsearch 8.