![](/img/trans.png)
[英]NodeJS returns no results with Elasticsearch / Mongoosastic
[英]Elasticsearch returns IndexMissingException
我正在尝试在 node.js 中使用 elasticSearch + mongoose(elmongo)实现一个搜索引擎。 每当我尝试运行搜索 API 时,我都会收到“错误”:“IndexMissingException[[ads] missing]”
这是代码
广告架构.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;
}
我已正确完成所有操作,但它只是不想返回搜索结果。
由于错误表明您的集群中没有名为“ads”的索引。 除非您在 elasticsearch 配置中将属性“action.auto_create_index”设置为 false,否则会自动创建索引。 您可以通过编程方式或通过运行 curl 请求来创建索引。 参考创建索引api。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.