MongoDB 使用 Mongoosastic 的 ElasticSearch 映射
MongoDB with ElasticSearch mapping with 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 });
我一直收到这个特定错误,但无法解决。如果你们能帮助我,我将不胜感激。
谢谢!
为 CallCenter 创建映射时出错 [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
我正在尝试使用 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 });
我一直收到这个特定错误,但无法解决。如果你们能帮助我,我将不胜感激。
谢谢!
为 CallCenter 创建映射时出错 [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