我已经安装了 Elasticsearch 和 Kibana。我有一个使用 NOdejs 和 MongoDB 的应用程序。这是我的架构配置:
var userSchema = new mongoose.Schema({
_id : { type: ObjectIdSchema , dropDups: true } ,
username : { type: String } ,
email : { type: String } ,
password : { type: String } ,
created : { type: String } ,
});
var Users = mongoose.model('Users', userSchema);
userSchema.plugin(mongoosastic,{
host:"127.0.0.1",
port: 9200,
protocol: "http",
index : "Users",
type: "Users",
});
Users.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);
}
});
但是我收到了这个错误:
Users.createMapping(function(err, mapping){
^
TypeError: Users.createMapping is not a function
我也尝试过这个,但遇到了同样的错误:
Users.createMapping({
"analysis" : {
"analyzer":{
"content":{
"type":"custom",
"tokenizer":"whitespace"
}
}
}
},function(err, mapping){
// do neat things here
});
如何修复它?
最佳答案
如果您使用 Elasticsearch 6.x,那么这是由于默认情况下将“字符串”类型转换为“文本”的不兼容问题造成的。
看看 ES 上的这篇文章 Strings are Dead...最后他们写了以下内容:
...That said, you should still look into upgrading them since we plan on removing this backward compatibility layer when we release Elasticsearch 6.0.
我已提交a pull request到 mongoosastic github repo 来修复这个问题以及该库的另一堆不兼容问题。如果您仍然希望使用这个库,您可以添加我的克隆存储库并进行修复,直到他们修复上游问题。
修复后的 Github 存储库是 https://github.com/avadhpatel/mongoosastic
关于node.js - mongoosastic,无法创建映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48693428/