【问题标题】:MongoDB with ElasticSearch mapping with MongoosasticMongoDB 与 ElasticSearch 与 Mongoosastic 的映射
【发布时间】:2016-12-08 02:29:17
【问题描述】:

我正在尝试使用 NodeJs 的 mongoosastic 插件将现有集合索引到 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 });

我不断收到此特定错误,但无法解决。如果你们能帮助我,我将不胜感激。

谢谢!

为呼叫中心创建映射时出错 [mapper_parsing_exception] 没有在字段 [子菜单] 上声明的类型 [混合] 的处理程序

【问题讨论】:

  • 什么是 CallCenterSubmenu.schema?
  • 我在第一个模式下方给出了子菜单模式。

标签: node.js mongodb elasticsearch mongoosastic


【解决方案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

【讨论】:

    猜你喜欢
    • 2017-03-25
    • 2020-01-29
    • 1970-01-01
    • 1970-01-01
    • 2021-04-20
    • 1970-01-01
    • 1970-01-01
    • 2018-07-19
    • 2017-01-03
    相关资源
    最近更新 更多