簡體   English   中英

Elasticsearch 返回 IndexMissingException

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM