0

ElasticSearch와 mongoosastic을 사용하여 MongoDB와 ElasticSearch간에 데이터를 동기화합니다.ElongSearch에 Mongo '_id'필드가 추가되지 않았습니다.

내가 겪고있는 문제는 ElasticSearch의 데이터를 검색 할 때 개체의 '_id'속성을 반환하지 않는다는 것입니다. 내가 잘못 말하고 있기 때문에 가능성이 높지만 문서를 찾을 수 없습니다.

내가 몽고에서 ElasticSearch에 동기화 mongoosastic 이야기하고있는 객체의 더미 예는 다음과 같습니다 :

var userSchema = new mongoose.Schema({ 
     name: {type:String,es_indexed:true}, 
     phone: {type:String,es_indexed:true}, 
     settings:{type:[String],es_indexed:true,index:'not_analyzed'} 
}, {id: true}); 

userSchema.plugin(mongoosastic,settings.elasticSearch); 

var User = mongoose.model('User', userSchema); 

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

내가 실행할 때 이 ElasticSearch에 _search, 나는 다음과 같은 구조

와 결과를 얻을 수
{ 
     "_index": "users", 
     "_type": "user", 
     "_id": "54b3ea9619160d0b0080d751", 
     "_score": 1, 
     "_source": { 
      "name": "John Smith", 
      "phone": "[email protected]", 
      "settings": [] 
     } 
    } 

_source 개체에 mongo 개체의 _id를 가져 오는 방법에 대한 아이디어가 있으십니까?

+0

'_source'에서 실제로 필요합니까? ' "_id": "54b3ea9619160d0b0080d751"'이 (가) 관련 ID가 아닙니까? – pickypg

답변

1

문제는 Elasticsearch 인덱스하지 않거나 기본적으로 id 필드를 저장하는 것입니다 :

ID와 유형과 관련된 인덱스 각 문서 _ID. _id 필드는 id를 색인화하고 가능하면 저장할 수 있습니다. 기본적으로 인덱싱되지 않으며 저장되지 않습니다 (따라서 생성되지 않습니다). 문제는 "저장"을 전달하는 방법이 될 것입니다

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-id-field.html

{ 
    "tweet" : { 
     "_id" : { 
      "index" : "not_analyzed", 
      "store" : true 
     } 
    } 
} 
:

_id 필드

적절한 매핑 속성 를 사용, 저장 가능한 색인을 활성화 할 수 있습니다 : mongoosastic의 createMapping 함수에 대한 참 매개 변수. createMapping 함수로 조금 놀아 보거나, 코드를 직접 수정하거나, 데이터를 색인하기 전에 수동으로 Elasticsearch 매핑을 만들어야 할 수도 있습니다.