2
내 단위 테스트 용 mongoosastic을 사용하여 모델을 자릅니다. 내 mongoose 스키마의 bulkindex를 수행하기 전에.mongoosastic 저장 데이터가 없습니다.
스키마 :
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(mongoosastic, {
esClient,
index: model,
});
절단 :
Model.esTruncate(function (err) {
if (err) {
console.error(err);
}
console.log("[ElasticSearch] Model removed")
Model.indexFiles();
});
인덱싱 :
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);
});
};
내가 로깅하고있어하지만 내 포스트 노선에서
Model.on('es-indexed', function (err, res) {
console.log('model added to es index');
});
, 내 ES는 빈 유지됩니다. 이유가 무엇인지 잘 모릅니다. 또한 Model.esSearch는 라이브러리에는 존재하지 않지만 라이브러리에는 문서화 된 기능입니다 https://github.com/mongoosastic/mongoosastic/issues/219 기본 esClient 사용을 진지하게 고려하고 있습니다. 이 라이브러리에 대한 귀하의 경험은 어떻습니까?