盆景自动索引

Bonsai automatic indexing

我使用 MongoDb 通过 Heroku 托管的快速应用进行存储。

我想通过 Bonsai Heroku 插件使用 ElasticSearch 为某些 MongoDb 集合提供搜索功能。

但是,根据Bonsai faq,不支持Elasticsearch River插件。

如果我不能使用 elasticsearch-river-mongodb?

这里是盆景支持的回答:

- 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.

所以我受Elaster启发制作了一个reindex脚本,它可以:

  • 要么定期调用 node-cron;

  • 或在事件检测后按需调用;触发事件我使用 mongo-oplog,像这样:

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