3

for my unit tests I am truncating my models using mongoosastic before I do a bulkindex of my mongoose schemas.

Schema:

model: {
    name: {type: String, required: true, es_indexed: true, index: 'not_analyzed'},
    aliases: {type: [String], es_indexed: true, index: 'not_analyzed'},
    birth: {type: Date, es_type: 'date', es_indexed: true, index: 
},

Schema plugin:

  schema.plugin(mongoosastic, {
    esClient,
    index: model,
  });

Truncating:

Model.esTruncate(function (err) {

      if (err) {
          console.error(err);
      }

      console.log("[ElasticSearch] Model removed")
      Model.indexFiles();
  });

Reindexing:

  Model.indexFiles = function () {
    console.log('[ElasticSearch] Start indexing ' + entityName + ' documents');

    var stream = model.synchronize();
    var count = 0;

    stream.on('data', function (err, doc) {
      count++;
    });
    stream.on('close', function () {
      console.log('[ElasticSearch] Indexed ' + count + ' ' + entityName + ' documents!');
    });
    stream.on('error', function (err) {
      console.log('mongoosastic ERROR');
      console.log(err);
    });
  };

However I'm logging:

Model.on('es-indexed', function (err, res) {
    console.log('model added to es index');
});

In my Post routes, my ES stays empty. I have no idea why? Also, Model.esSearch is a function that doesn't exist n the library however it is documented https://github.com/mongoosastic/mongoosastic/issues/219 I'm Seriously considering to start using the default esClient. What are your experiences with this library?

jo v
  • 302
  • 5
  • 14

1 Answers1

0

this might be hard to find, but in my case it was not the library, it was my ES cluster health status that was in RED because I didn't have enough disk space. You may try the following:

  1. stop your local ES instance
  2. clear up some diskspace
  3. restart your ES
  4. truncate indeces using CURL (curl -XDELETE 'http://localhost:9200/model/')
  5. Reindex your models
  6. If there's still issues, take in account that updating records in ES is semi realtime, so there might be some delay and logging should be done in callbacks. Run your tests after a short delay after truncating and bulk indexing

That did it for me...

jo v
  • 302
  • 5
  • 14