node.js - Elasticsearch 返回 IndexMissingException

标签 node.js elasticsearch mongoose elasticsearch-plugin

我正在尝试使用elasticSearch + mongoose(即elmongo)在node.js 中实现搜索引擎。每当我尝试运行搜索 api 时,我都会得到 “错误”:“IndexMissingException[[广告]缺失]”

这是代码

广告模式.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 请求来创建索引。 引用create index api.

关于node.js - Elasticsearch 返回 IndexMissingException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29724800/

相关文章:

node.js - 如何更新 Mongo 集合中的部分?

node.js - 在 Mongoose 模型中使用 id 属性有危险吗?

javascript - Typescript:忽略与基本类型并行的自定义类型

javascript - 不兑现的 promise

elasticsearch - Logstash中的日期翻译以进行Elasticsearch

elasticsearch - Elasticsearch `scan`和 `scroll`之后的文档计数不正确,然后 `refresh`和 `flush`

elasticsearch - 是否可以在 elasticsearch 聚合中执行相当于 SQL "HAVING"的操作?

javascript - 如何从服务器端javascript获取来自不同域的.txt文件并将其获取客户端

javascript - 从 MongoDB 获取数据的 Node.js REST API

node.js - 为什么 mongoDB 不会更新我的用户条目的 “Date” 字段?