我的架构看起来像这样mongoose
:
var LocationSchema = new Schema({
id: ObjectId,
geo: {
type: {
type: String,
required: true,
enum: ['Point', 'LineString', 'Polygon'],
default: 'Point'
},
coordinates: [{
type: Number,
es_lat_lon: true,
es_type: 'geo_point'
}]
}
});
然后我添加mongoosastic
插件来mongoose
启动模型并创建映射mongoosastic
var esClient = new elasticsearch.Client({
host: config.es_url,
requestTimeout: Infinity,
keepAlive: true
});
LocationSchema.plugin(mongoosastic, { esClient: esClient })
var Location = mongoose.model('Location', LocationSchema);
/**
* mongoosastic create mappings
*/
Location.createMapping(function(err, mapping) {
if (err) {
console.log('error creating mapping (you can safely ignore this)');
console.log(err);
} else {
console.log('mapping created!');
console.log(mapping);
}
});
现在我得到这个错误[Error: MapperParsingException[No handler for type [{default=Point, enum=[Point, LineString, Polygon], required=true, type=string}] declared on field [geo]]]
日志中的完整错误:
{
[Error: MapperParsingException[No handler for type [{default=Point, enum=[Point, LineString, Polygon], required=true, type=string}] declared on field [geo]]]
status: '400',
displayName: 'BadRequest',
message: 'MapperParsingException[No handler for type [{default=Point, enum=[Point, LineString, Polygon], required=true, type=string}] declared on field [geo]]'
}
我的问题是我这样做是完全错误的还是我只是错过了一些小东西?我这样做的方式适用于mongoose
,只是mongoosastic
遇到了麻烦,我理解为什么,但我不能成为第一个遇到这个问题的人(为什么mongoosastic
遇到麻烦是它看到type
并且不期望它有一个类型 - 在至少那是我认为它遇到麻烦的地方)。