私の目標はmongoosastic検索で特定のフィールドを移入することですが、私は以下のコードをすれば、それは常にmongoosasticに入力するにはどうすればよいですか?
を返します。ここでは、コード
var mongoose = require('mongoose');
var Category = require('./category');
var mongoosastic = require('mongoosastic');
var Schema = mongoose.Schema;
var ProductSchema = new Schema({
category: { type: Schema.Types.ObjectId, ref: 'Category', es_schema: Category, es_indexed:true, es_select: 'name'},
name: String,
price: Number,
image: String
});
ProductSchema.plugin(mongoosastic, {
hosts: [
'localhost:9200'
],
populate: [
{path: 'category', select: 'name'}
]
});
module.exports = mongoose.model('Product', ProductSchema);
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var CategorySchema = new Schema({
name: { type: String, unique: true, lowercase: true}
});
module.exports = mongoose.model('Category', CategorySchema);
api.js
ですrouter.post('/search', function(req, res, next) {
console.log(req.body.search_term);
Product.search({
query_string: { query: req.body.search_term }
}, function(err, results) {
if (err) return next(err);
res.json(results);
});
});
mongoosasticに特定のカテゴリを設定するにはどうすればよいですか?あなたはあなたのコードで
populate: [
{path: 'categories', select: 'name'}
]
しかしcategories
を使用している
これはうまくいきましたか?私は居住するときに0ヒットを得る同様の問題があります。私は何度もドキュメントを読んだことがありますが、どこが間違っているのか分かりません。あなたは洞察力を提供することができます:http://stackoverflow.com/questions/37758652/mongoosastic-elastic-search-will-not-return-any-hits-when-populating – someoneHere
この問題を解決しますか? – Mikhail