node.js - mongoosastic,无法创建映射

标签 node.js mongodb elasticsearch mongoosastic

我已经安装了 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/

相关文章:

node.js - 使用 Protractor 如何在不为每个规范文件关闭浏览器的情况下运行多个规范文件

node.js - 使用 native Node 插件时如何自动下载外部 (C++) 库?

javascript - node.js 事件队列在哪里?

javascript - Mongoose:使用 pass 选项 'useUnifiedTopology: true' 导致错误处理失败

elasticsearch - 问题ELK:ElasticSearch + kibana + Searchguard

javascript - 使用 Node 和 Angular 创建新应用程序以进行自动登录 --- 需要见解

mongodb - Schema - 图表创建者 mongodb

.net - 为 SignalR 实现背板和消息总线

mysql - 我的 Web 应用程序需要 mongodb 或 mysql 吗?

elasticsearch - Logstash GROK 解析可变长度的键/值对集