Search code examples
node.jselasticsearchscalabilityseparation-of-concernselasticsearch-plugin

ElasticSearch with nodejs : why use the npm module?


I am about to add the search engine to my Node application. I can see there is a npm package for ElasticSearch.

But why not simply using ElasticSearch standalone instead of nesting it with the application code?

The use case for me is:

  • Data is in a MySQL database with a true entity-relationship-diagram.
  • I intend to use Docker containers to ship my application elements (which can be modified as for now).
  • The results' positioning is intended to be complex, and I thought of a nightly cronjob that would re-evaluate the documents/results, because they depend on moving data (user's reputation or popular sales, for instance).

Don't you think a standalone ElasticSearch instance / grid is more enviable? I imagine that it would be more scalable, more secure, and easier to deploy in a cloud, for instance...


Solution

  • The npm package you refer to is a Javascript client for Node and in-browser use, that can be used to perform searches, index (create/insert) documents on the Elasticsearch server. What you refer to as Elasticsearch standalone is the server and yes, that can and should be entirely separate from the client application code.

    It is definitely possible to not use a client library and access the Elasticsearch REST API directly using whatever HTTP client code, but then it is too easy to reinvent the wheel, badly.