Elasticsearch returns IndexMissingException
Elasticsearch returns IndexMissingException
我正在尝试使用 elasticSearch + mongoose 在 node.js 中实现一个搜索引擎,它是 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;
}
我都做对了,只是不想return搜索结果。
如错误提示,您的集群中没有名为 'ads' 的索引。除非您在 elasticsearch 配置中将 属性 "action.auto_create_index" 设置为 false,否则会自动创建索引。您可以通过编程方式或通过 运行 curl 请求创建索引。
参考create index api.
我正在尝试使用 elasticSearch + mongoose 在 node.js 中实现一个搜索引擎,它是 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;
}
我都做对了,只是不想return搜索结果。
如错误提示,您的集群中没有名为 'ads' 的索引。除非您在 elasticsearch 配置中将 属性 "action.auto_create_index" 设置为 false,否则会自动创建索引。您可以通过编程方式或通过 运行 curl 请求创建索引。 参考create index api.