我正在使用ElasticSearch和mongoosastic来同步MongoDB和ElasticSearch之间的数据。未在ElasticSearch中添加Mongo'_id'字段
我遇到的问题是,当我对ElasticSearch中的数据执行搜索时,它不返回对象的'_id'属性。很可能是因为我错误地告诉它,但我找不到任何文档。
,我告诉mongoosastic从蒙戈同步到ElasticSearch对象的虚设例子如下所示:
var userSchema = new mongoose.Schema({
name: {type:String,es_indexed:true},
phone: {type:String,es_indexed:true},
settings:{type:[String],es_indexed:true,index:'not_analyzed'}
}, {id: true});
userSchema.plugin(mongoosastic,settings.elasticSearch);
var User = mongoose.model('User', userSchema);
User.createMapping(function(err, mapping){
if(err){
console.log('error creating User mapping (you can safely ignore this)');
console.log(err);
}else{
console.log('User mapping created!');
console.log(mapping);
}
});
当运行一个上ElasticSearch _search,我得到具有以下结构的
结果{
"_index": "users",
"_type": "user",
"_id": "54b3ea9619160d0b0080d751",
"_score": 1,
"_source": {
"name": "John Smith",
"phone": "[email protected]",
"settings": []
}
}
任何想法如何获得mongo对象的_id到_source对象?
你真的需要'_source'吗?是否“_id”:“54b3ea9619160d0b0080d751”'不是相关的ID? – pickypg