2016-07-07 11 views
2

私の単体テスト用mongoosasticを使用して私のモデルを切り捨てる前に、私はmongooseスキーマのbulkindexを実行します。mongoosastic save on data on save

スキーマ:

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(mongoosastic, { 
    esClient, 
    index: model, 
    }); 

切捨て:

Model.esTruncate(function (err) { 

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

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

インデックスの再作成:

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); 
    }); 
    }; 
私がログインしてい

しかし:私のポストルートで

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

を、私のESは空のままです。 なぜ私は考えていない? また、Model.esSearchはライブラリには存在しませんが、文書化されている関数ですhttps://github.com/mongoosastic/mongoosastic/issues/219 デフォルトのesClientの使用を真剣に考えています。 この図書館でのあなたの経験は何ですか?

答えて

0

これは見つけるのが難しいかもしれませんが、私の場合はライブラリではありませんでした。十分なディスク容量がないため、ESクラスタの正常性ステータスが赤でした。 次の試みることがあります。お近くのESのインスタンス

  1. が停止
  2. までいくつかのディスク領域
  3. 再起動
  4. はCURLに(カール-XDELETE 'http://localhost:9200/model/')
  5. 再インデックスを使用してindecesを切り捨てあなたのESをクリアあなたのモデル
  6. 問題がまだ残っている場合は、ESでレコードを更新するのがセミリアルタイムであるため、コールバックで遅延やログを行う必要があるかもしれません。

    ...私のためにそれをやった

を切り捨てとバルクインデックス後の短い遅延の後にテストを実行します