私はmongoosasticを備えたnodejsサーバーを持っており、インデックスだけではなく、ネストされた検索結果をオブジェクトとして取得しようとしています。
それは私のコードです:
require('../server/serverInit');
var elasticsearch = require('elasticsearch');
var esclient = new elasticsearch.Client({
host: 'localhost:9200',
log: 'trace'
});
var Schema = mongoose.Schema;
var mongoosastic = require('mongoosastic');
var elasticsearch = require('elasticsearch');
var esclient = new elasticsearch.Client({
host: '127.0.0.1:9200',
log: 'trace'
});
global.DBModel = {};
/**
* StoreSchema
* @type type
*/
var storeSchema = global.mongoose.Schema({
Name: {type: String, es_indexed: true},
Email: {type: String, es_indexed: true},
.....
_articles: {type: [articleSchema],
es_indexed: true,
es_type: 'nested',
es_include_in_parent: true}
});
/**
* ArtikelSchema
* @type Schema
*/
var articleSchema = new Schema({
Name: {type: String, es_indexed: true},
Kategorie: String,
....
_stores: {type: [storeSchema],
es_indexed: true,
es_type: 'nested',
es_include_in_parent: true}
});
storeSchema.plugin(mongoosastic, {
esClient: esclient
});
articleSchema.plugin(mongoosastic, {
esClient: esclient
});
global.DBModel.Artikel = global.mongoose.model('Artikel', articleSchema);
global.DBModel.Store = global.mongoose.model('Store', storeSchema);
このサンプルコードを持つルート「/ search」から検索を開始すると:
global.DBModel.Artikel.search({
query_string: {
query: "*"
}
}, {
hydrate: true
}, function (err, results) {
if (err)
return res.send(500, {error: err});
res.send(results);
});
私はこの結果を得る:
...
{
"_id": "56ab6b15352a43725a21bc92",
"stores": [
"56ab6b03352a43725a21bc91"
],
"Name": "daaadd",
"ArtikelNummer": "232",
"__v": 0,
"_stores": []
}
]
}
}
ID「56ab6b03352a43725a21bc91」の代わりにオブジェクトを直接取得するにはどうすればよいですか?