for my unit tests I am truncating my models using mongoosastic before I do a bulkindex of my mongoose schemas.
Schema:
model: {
name: {type: String, required: true, es_indexed: true, index: 'not_analyzed'},
aliases: {type: [String], es_indexed: true, index: 'not_analyzed'},
birth: {type: Date, es_type: 'date', es_indexed: true, index:
},
Schema plugin:
schema.plugin(mongoosastic, {
esClient,
index: model,
});
Truncating:
Model.esTruncate(function (err) {
if (err) {
console.error(err);
}
console.log("[ElasticSearch] Model removed")
Model.indexFiles();
});
Reindexing:
Model.indexFiles = function () {
console.log('[ElasticSearch] Start indexing ' + entityName + ' documents');
var stream = model.synchronize();
var count = 0;
stream.on('data', function (err, doc) {
count++;
});
stream.on('close', function () {
console.log('[ElasticSearch] Indexed ' + count + ' ' + entityName + ' documents!');
});
stream.on('error', function (err) {
console.log('mongoosastic ERROR');
console.log(err);
});
};
However I'm logging:
Model.on('es-indexed', function (err, res) {
console.log('model added to es index');
});
In my Post routes, my ES stays empty. I have no idea why? Also, Model.esSearch is a function that doesn't exist n the library however it is documented https://github.com/mongoosastic/mongoosastic/issues/219 I'm Seriously considering to start using the default esClient. What are your experiences with this library?