我正在尝试使用mongoosastic进行搜索,但我一直收到'No Living connections‘错误和映射问题
下面是代码
var mongoose = require('mongoose');
var mongoosastic = require('mongoosastic');
var Schema = mongoose.Schema;
var JobSchema = Schema({
category: { type: Schema.Types.ObjectId, ref: 'Category', es_indexed:true},
title: { type: String, es_indexed:true },
});
JobSchema.plugin(mongoosastic);
module.exports = mongoose.model('Job', JobSchema);routes.js
var Job = require('../models/job');
Job.createMapping(function(err, mapping) {
if (err) {
console.log('error creating mapping (you can safely ignore this)');
console.log(err);
} else {
console.log('mapping created!');
console.log(mapping);
}
});
app.post('/search', function(req, res, next) {
Job.search({query_string: {query: req.body.q}}, function(err, results) {
if (err) return next(err);
res.send(results);
});
});我一直收到这个错误,

有使用mongoosastic经验的人能告诉我,我如何解决这个问题吗?
发布于 2015-11-24 12:37:13
当将插件添加到你的JobSchema模型中时,你需要传递第二个关于如何连接到Elasticsearch的参数:
JobSchema.plugin(mongoosastic, {
hosts: [
'localhost:9200'
]
});您还可以重用Elasticsearch客户端对象(如果已准备好)。
var esClient = new elasticsearch.Client({host: 'localhost:9200'});
JobSchema.plugin(mongoosastic, {
esClient: esClient
})发布于 2015-12-03 19:35:46
我也面临着同样的问题,但我现在用下面的方法解决了
非常简单:您必须在本地或其他任何地方安装elastic search
发布于 2015-12-01 23:38:15
我认为你必须创建一个客户端,并将其传递到插件中,但使用ip地址对我来说是有效的。
// http://127.0.0.1:9200 == http://localhost:9200
var esClient = new elasticsearch.Client({host: 'http://127.0.0.1:9200'});
JobSchema.plugin(mongoosastic, {
esClient: esClient
})引用这个答案:https://stackoverflow.com/a/30204512/1146562
根据这个答案,您可以直接将host传递到插件中,而不必创建客户端。
https://stackoverflow.com/questions/33869013
复制相似问题