【问题标题】:Elasticsearch returns IndexMissingExceptionElasticsearch 返回 IndexMissingException
【发布时间】: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


    【解决方案1】:

    正如错误提示,您的集群中没有名为“ads”的索引。除非您在 elasticsearch 配置中将属性“action.auto_create_index”设置为 false,否则会自动创建索引。您可以通过编程方式或通过运行 curl 请求来创建索引。 参考create index api.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-14
      • 2015-07-29
      • 1970-01-01
      • 2014-04-25
      • 2020-02-07
      • 1970-01-01
      相关资源
      最近更新 更多