const mongoose = require(‘mongoose‘) const mongoosastic = require(‘mongoosastic‘) let schema = new mongoose.Schema({}) // 载入插件 schema.plugin(mongoosastic, { hosts: [process.env.ES_HOST] }) let Model = mongoose.model(‘conversation‘, schema) // 同步老数据 let stream = Model.synchronize() let count = 0; stream.on(‘data‘, (err, doc) => count++) stream.on(‘close‘, () => console.log(`[es]`, `indexed`, count, `documents`)) stream.on(‘error‘, err => console.log(`[es]`, `error`, err))
原文:https://www.cnblogs.com/kiancyc/p/14356178.html