我试着使用mongoosastic供搜索,但一直收到“没有生活连接”的错误和映射问题Mongoosastic - {[错误:没有生活连接]消息:“没有生活连接”}
下面的代码
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经验的人都告诉我,我该如何解决这个问题?
可能是愚蠢的问题,而是你的elasticsearch服务运行? –
@EvaldasBuinauskas我需要运行它吗? –
那么,根据我的理解,mongoosastic应该将它索引到Elasticsearch。所以你必须安装它,作为服务运行并配置你的代码来连接它。至少这就是我理解它如何看待文档。 –