I'm trying to index data from mongo DB to elasticsearch using mongoose, my documents are already existing or maybe there is a way to indexing all data automatically without a schema please help me!
This is my document:
This is my node code:
const mongoose = require('mongoose');
const mongoosastic = require('mongoosastic');
mongoose.connect('mongodb://localhost:27017/landingZoneDB');
var commentsSchema=new mongoose.Schema({
joined_date:{type:String} ,
comment_date:{type:String},
comment_body:{type:String},user_link:{type:String} ,
posts_count:{type:String}, user_name:{type:String}});
var DNMAvengers_tbSchema = new mongoose.Schema({
crawl_date:{type:String}
, views:{type:String}
, replies:{type:String}
,title:{type: String}
,comments: [commentsSchema]
,link:{type: String}
,forum_title:{type: String}
,avatar_details: {avatar_name:{type: String} ,avatar_pass:{type: String}, avatar_user:{type:String}, avatar_email:{type: String} }
});
var comments = mongoose.model('comments', commentsSchema);
DNMAvengers_tbSchema.plugin(mongoosastic);
var DNMAvengers_tb = mongoose.model('DNMAvengers_tb', DNMAvengers_tbSchema)
, stream = DNMAvengers_tb.synchronize()
, count = 0;
var stream = DNMAvengers_tb.synchronize({}, {saveOnSynchronize: true})
stream.on('data', function(err, doc){
count++;
});
stream.on('close', function(){
console.log('indexed ' + count + ' documents!');
});
stream.on('error', function(err){
console.log(err);
});
That my result:
C:\Users\Administrator>node RUN.js (node:2816) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect. (node:2816) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor. indexed 0 documents!
