node.js - 具有ElasticSearch映射和Mongoosastic的MongoDB

标签 node.js mongodb elasticsearch mongoosastic

我正在尝试使用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 });

我不断收到此特定错误,但无法解决。谢谢您能帮助我。

谢谢!

为CallCenters创建映射时出错[mapper_parsing_exception]在字段[submenu]上未声明类型[mixed]的处理程序

最佳答案

我想问题是那条线:

 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

关于node.js - 具有ElasticSearch映射和Mongoosastic的MongoDB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38725441/

相关文章:

elasticsearch - 我可以在同一台服务器上运行Logstash的多个实例吗?

javascript - 类型错误 : Object #<IncomingMessage> has no method 'render'

node.js - 如何在node.js中使用ejs使用特定文件夹中的每个图像?

html - 从 npm 脚本在浏览器中打开 html 文件

node.js - 如何通过 REST API 微服务(使用 Express 构建)将 MongoDB 更改流与 Node js 一起使用

ruby-on-rails - 如何以编程方式获取 Mongoid 正在写入的当前数据库?

Jade 模板中的 Javascript 函数调用不起作用

python - 如何在 pymongo 中禁用 '_id'

elasticsearch - 在Elasticsearch中生成URL字符串的匹配项

elasticsearch - Elasticsearch父子关系缩放