我试图使用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经验的人都可以告诉我,我该如何解决这个问题?
最佳答案 我也面临同样的问题,但我现在使用以下方法解决了
Its very simple : you have to install elastic search in your local or anywhere else
>下载弹性搜索http://www.elastic.co/downloads/elasticsearch
>提取文件夹
>从cmd或Treminal查找bin文件夹转到文件夹,然后在该文件夹中运行弹性搜索脚本
>并且在nodejs代码中,默认情况下它将链接到localhost:9200,因此无需使用
new elasticsearch.Client({host:’localhost:9200′}),但如果你的弹性搜索部署在其他地方,那么你必须使用上面的客户端方法