简体   繁体   中英

Elasticsearch returns IndexMissingException

I'm trying to implement a search engine in node.js using elasticSearch + mongoose which is elmongo. Whenever i try to run a search api i get "error": "IndexMissingException[[ads] missing]"

Here's the code

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;
  }

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. Index is automatically created unless you have set the property "action.auto_create_index" to false in your elasticsearch configuration. You can create the index programmatically or by running a curl request. Refer to create index api.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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