airsoftFreak
airsoftFreak

Reputation: 1598

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.

Upvotes: 3

Views: 7669

Answers (1)

Prabin Meitei
Prabin Meitei

Reputation: 2000

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.

Upvotes: 2

Related Questions