Bonsai automatic indexing

364 views Asked by At

I use MongoDb for storage with an express, Heroku-hosted app.

I would like to provide search capabilities to some MongoDb collections, using ElasticSearch via the Bonsai Heroku add-on.

However, according to the Bonsai faq, Elasticsearch River plugins are not supported.

How can I automatically re-index my MongoDb collections (when a MongoDb document is created/updated/deleted) on Bonsai, using custom mapping, if I cannot use elasticsearch-river-mongodb?

1

There are 1 answers

0
Manube On BEST ANSWER

Here is the answer by Bonsai support:

- You could always set up a script with a curl command to index the MongoDB collections, then use cron to run the script at regular intervals.
- You could also use an Elasticsearch client to index collections in some cases.

So I made a reindex script inspired by Elaster, which can:

  • either be called at regular intervals with node-cron;

  • or be called on demand, following event detection; to trigger events I use mongo-oplog, like so:

    oplog.on('insert', function (doc) {
      reindex();
    });