简体   繁体   English

Elasticsearch 返回 IndexMissingException

[英]Elasticsearch returns IndexMissingException

I'm trying to implement a search engine in node.js using elasticSearch + mongoose which is elmongo.我正在尝试在 node.js 中使用 elasticSearch + mongoose(elmongo)实现一个搜索引擎。 Whenever i try to run a search api i get "error": "IndexMissingException[[ads] missing]"每当我尝试运行搜索 API 时,我都会收到“错误”:“IndexMissingException[[ads] missing]”

Here's the code这是代码

advertisingSchema.js广告架构.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 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;
  }

I've done everything correctly, but its just doesn't want to return the search result.我已正确完成所有操作,但它只是不想返回搜索结果。

As the error suggest there is no index named 'ads' in your cluster.由于错误表明您的集群中没有名为“ads”的索引。 Index is automatically created unless you have set the property "action.auto_create_index" to false in your elasticsearch configuration.除非您在 elasticsearch 配置中将属性“action.auto_create_index”设置为 false,否则会自动创建索引。 You can create the index programmatically or by running a curl request.您可以通过编程方式或通过运行 curl 请求来创建索引。 Refer to create index api.参考创建索引api。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM