【发布时间】:2015-06-25 19:34:48
【问题描述】:
我正在尝试在 node.js 中使用 elasticSearch + mongoose(即 elmongo)实现搜索引擎。每当我尝试运行搜索 api 时,我都会得到 "error": "IndexMissingException[[ads] missing]"
这是代码
advertisingSchema.js
var mongoose = require('mongoose');
var elmongo = require('elmongo');
var Schema = mongoose.Schema;
var AdSchema = new Schema({
title: String,
description: String,
category: String,
phoneNumber: { type: Number, unique: true},
photos: [{ type: String }],
created: { type: Date, default: Date.now},
price: Number,
password: String
});
AdSchema.plugin(elmongo);
module.exports = mongoose.model('Ad', AdSchema
);
api.js
var Ad = require('../models/advertising');
module.exports = function(app, express) {
var api = express.Router();
Ad.sync(function(err) {
console.log("Check the number sync");
})
api.post('/search', function(req, res) {
Ad.search(req.body, function(err, result){
if(err) {
res.send(err);
return;
}
res.json(result);
});
});
return api;
}
我做的一切都正确,但它只是不想返回搜索结果。
【问题讨论】:
标签: node.js elasticsearch mongoose elasticsearch-plugin