Mongoosastic - message {Error: No Living connections]: "No live connection"}

I try to use mongoosastic to search, but I keep getting the “Lack of links” error and display issues

Here is the code

var mongoose = require('mongoose');
var mongoosastic = require('mongoosastic');
var Schema = mongoose.Schema;


var JobSchema = Schema({
  category: { type: Schema.Types.ObjectId, ref: 'Category', es_indexed:true},
  title: { type: String, es_indexed:true },

});

JobSchema.plugin(mongoosastic);
module.exports = mongoose.model('Job', JobSchema);

routes.js

var Job = require('../models/job');

Job.createMapping(function(err, mapping) {
  if (err) {
    console.log('error creating mapping (you can safely ignore this)');
    console.log(err);
  } else {
    console.log('mapping created!');
    console.log(mapping);
  }
});

app.post('/search', function(req, res, next) {
    Job.search({query_string: {query: req.body.q}}, function(err, results) {
        if (err) return next(err);
        res.send(results);
    });
});

I keep getting this error

enter image description here

Can anyone with experience using mongoosastic say how can I solve this problem?

+4
source share
3 answers

I am also facing the same problem, but now I decided to use the method below

It is very simple: you need to set up elastic search in a local or other place

+1

JobSchema , Elasticsearch:

JobSchema.plugin(mongoosastic, {
  hosts: [
    'localhost:9200'
  ]
});

Elasticsearch, .

var esClient = new elasticsearch.Client({host: 'localhost:9200'});
JobSchema.plugin(mongoosastic, {
  esClient: esClient
})
0

I think you need to create a client and pass it to the plugin, but use the ip addresses that work for me.

// http://127.0.0.1:9200 == http://localhost:9200

var esClient = new elasticsearch.Client({host: 'http://127.0.0.1:9200'});
JobSchema.plugin(mongoosastic, {
    esClient: esClient
})

Note: if you have not used elasticsearch before, you may have to reindex your documents (I should have, but I might have done something wrong)

Link to this answer: fooobar.com/questions/1617044 / ...

from this answer you can pass the host directly to the plugin and not create a client.

0
source

Source: https://habr.com/ru/post/1617042/


All Articles