2

ElasticSearch と mongoosastic を使用して、MongoDB と ElasticSearch の間でデータを同期しています。

私が抱えている問題は、ElasticSearch のデータに対して検索を実行すると、オブジェクトの '_id' プロパティが返されないことです。おそらく私が間違って伝えているためですが、ドキュメントが見つかりません。

Mongo から ElasticSearch に同期するように mongoosastic に指示しているオブジェクトのダミーの例を以下に示します。

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": "JohnSmith@gmail.com",
           "settings": []
        }
     }

mongo オブジェクトの _id を _source オブジェクトに取得する方法はありますか?

4

1 に答える 1