0

私はmongooseスキーマを持っています。これに対してセーブまたは更新が呼び出されると、弾性検索ソースも更新されます。 statusの値がdraftの場合、弾性検索を更新しないでください。次のスキーマで変更を行うことでどのように達成できますか?マングースを使用したElastic Search Clientによる条件付き更新

var TestShcema = new mongoose.Schema({ 
     custom_id:{ 
      type:String, 
      required: true, 
      index: {unique: true}, 
      es_indexed: true, 
      es_index:"analyzed", 
      es_index_analyzer:"autocomplete_analyzer" 
     }, 
     title:{ 
      type:String, 
      index: {unique: false}, 
      es_indexed: true, 
      es_index:"analyzed", 
      es_index_analyzer:"autocomplete_analyzer" 
     }, 
     status:{ 
      type:String, 
      index: {unique: false}, 
      es_indexed: true, 
      es_index:"analyzed", 
      es_index_analyzer:"autocomplete_analyzer" 
     } 
    }); 
    //Hook with Elastic Search 
    var esClient = new elasticsearch.Client({host: config.elasticsearch.host}); 

    TestShcema.plugin(mongoosastic, { 
     esClient: esClient 
    }); 

    var Test = mongoose.model('Test', TestShcema); 

    module.exports = Test; 

答えて

1

あなたは、いくつかの特定の条件に基づいてElasticsearchするインデックスにモデルをフィルタ機能を指定することができますnpmjs

から濾過インデックス

コピーペーストを使用することができます。

フィルタリング関数は、Elasticsearchへのインデックス付けを無視する条件に対してTrueを返す必要があります。作品のモデルはそのジャンルとして「アクション」を有するの

var MovieSchema = new Schema({ 
    title: {type: String}, 
    genre: {type: String, enum: ['horror', 'action', 'adventure', 'other']} 
}); 

MovieSchema.plugin(mongoosastic, { 
    filter: function(doc) { 
    return doc.genre === 'action'; 
    } 
}); 

インスタンスはElasticsearchにインデックス付けされることはありません。

https://www.npmjs.com/package/mongoosastic#filtered-indexing

あなたはこの

TestShcema.plugin(mongoosastic, { 
    filter: function(doc) { 
    return doc.status === 'draft'; 
    } 
}); 
ような何かを行うことができます
関連する問題