zhr85210078 / node-mongodb-es-connector

nodejs mongodb elasticsearch synchrodata(mongodb和es同步数据)
https://zhr85210078.github.io/node-mongodb-es-connector/#/
MIT License
77 stars 17 forks source link

自动同步问题 #20

Open glacierck opened 5 years ago

glacierck commented 5 years ago

服务启动时的全量同步有调用e_pipeline,但运行期间mongo数据修改后仅仅是同步了指定的m_collectionname,没有执行e_pipeline。

PS。我在自定义e_pipeline里对m_collectionname里的指定属性做了多个拷贝并正则替换成新文档,然而在自动同步过程中这些字段都没被更新 bulkDataAndPip 里的日志:

--启动时的bulk

[
    {
        "index":{
            "_index":"corpus",
            "_type":"contents",
            "_id":"ImQs6IdHp"
        }
    },
    {
         "title":"doc2019-03-24-2",
         "comments":"11111"
    }
]

--更新时的bulk

[
    {
        "update":{
            "_index":"corpus",
            "_type":"contents",
            "_id":"ImQs6IdHp"
        }
    },
    {
        "doc":{
            "title":"doc2019-03-24-2",
            "comments":"22222"
        }
    }
]
glacierck commented 5 years ago

解决方案。修改getUpdateMasterDocBulk :

return new Promise(function (resolve, reject) {
        var bulk = [];
        var item = {};
        item.doc = opDoc;
        bulk.push({
            index: {
                _index: watcher.Content.elasticsearch.e_index,
                _type: watcher.Content.elasticsearch.e_type,
                _id: id
            }
        }, opDoc);
        return resolve(bulk);
    });
zhr85210078 commented 5 years ago

这个方法主要是为了做mongodb的原子更新用的,因为oplog里面返回的数据不一定是全部的,改成上面那种方法就是全量替换elasticsearch里面的数据,如果你的应该场景是每次更新操作oplog返回的数据是全量的,可以改成上面的那种,否则你会发现elasticsearch里面的数据会丢节点 $38015BBFE04B17B3