2016-08-02 106 views
0

我試圖使用mongoosastic插件爲NodeJs將現有集合索引到ElasticSearch。這是我的架構:MongoDB與MongoDB的ElasticSearch映射

const callCenterSchema = new mongoose.Schema({ 
    _owner : { type: mongoose.Schema.Types.ObjectId, ref: 'User', es_type: 'object' }, 
    ivrs: [{ 
     name: { 
      type: String, 
      es_type: 'string' 
     }, 
     ivrType: { 
      type: String, 
      default: 'mobile', 
      enum: ['mobile', 'website'], 
      es_type: 'string' 
     }, 
     submenu: { 
      type: [ CallCenterSubmenu.schema ], 
      es_type: 'nested', 
      es_include_in_parent: true 
     } 
    }] 
}); 

callCenterSchema.plugin(mongoosastic, { 
    esClient: require('tusla/lib/db/elastic').elastic, 
    populate: [ 
     { path: '_owner' } 
    ] 
}); 

let CallCenter = mongoose.model('CallCenter', callCenterSchema); 
CallCenter.synchronize() 

CallCenter.createMapping(function(err, mapping) { 
    if (err) { 
    console.error('Error creating mapping for CallCenters', err.message); 
    } 
}); 


module.exports = CallCenter; 

我的子菜單的模式是這樣的:

const callcenterSubmenuSchema = new mongoose.Schema({ 
    name: String, 
    key: String, 
    waitTime: { 
     type: Number 
    }, 
    waitSuffix: String, 
    numberOrLink: String, 
    auth: { 
     canBeSkipped: String, 
     fields: { 
      type: Array, 
      es_type: 'object' 
     }, 
     verification: String, 
     regExp: String 
    }, 
    submenu: [this] 
}, { _id: false }); 

我不斷收到此特定錯誤,但未能解決這個問題。我很感激你們能否幫助我。

謝謝!對於CallCenters

錯誤創建映射[mapper_parsing_exception]沒有處理程序類型[混合]現場宣佈[子]

+0

什麼是CallCenterSubmenu.schema? – alpert

+0

我已經在第一個模式下面給出了子菜單模式。 – Yagiz

回答

1

我想這個問題是該行:

type: [ CallCenterSubmenu.schema ] 

在錯誤信息,它說:

No handler for type [mixed] declared on field [submenu] 

所以您要指定submenu字段的類型爲fixed(或elasticsearch推斷它,因爲我不肯定),因爲我知道沒有類型爲mixed。所以ES引發了這個例外。您必須指定有效類型:https://www.elastic.co/guide/en/elasticsearch/reference/master/mapping-types.html