首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Mongoosastic进行ElasticSearch映射的MongoDB

使用Mongoosastic进行ElasticSearch映射的MongoDB
EN

Stack Overflow用户
提问于 2016-08-03 00:03:09
回答 1查看 1.5K关注 0票数 0

我正在尝试使用NodeJs的mongoosastic插件将现有的集合索引到ElasticSearch。这是我的方案:

代码语言:javascript
复制
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;

我的子菜单模式是这样的:

代码语言:javascript
复制
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创建映射时出错字段子菜单上声明的混合类型没有处理程序

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-03 06:56:43

我想问题出在这一行:

代码语言:javascript
复制
 type: [ CallCenterSubmenu.schema ]

在错误消息中,它说:

代码语言:javascript
复制
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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38725441

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档