2016-08-02 111 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