0

나는 mongoose 스키마를 가지고 있으며 저장 또는 업데이트가 호출 될 때 탄성 검색 소스도 업데이트됩니다. 값이 draft 일 때 탄성 검색을 업데이트해서는 안되는 한 가지 문제가 있습니다. 다음 스키마에서 수정을 수행하면 어떻게 달성 할 수 있습니까?mongoose가 포함 된 Elastic Search 클라이언트의 조건부 업데이트

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

당신은 당신은 인덱스 필터 함수에게 모델을 지정할 수 있습니다 필터링 인덱싱에게 npmjs

에서

복사 붙여 넣기를 사용할 수는 일부 특정 조건에 따라 Elasticsearch합니다.

필터링 기능은 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'; 
    } 
}); 
과 같은 작업을 수행 할 수 있습니다