我試着使用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。所以你必須安裝它,作爲服務運行並配置你的代碼來連接它。至少這就是我理解它如何看待文檔。 –