【问题标题】:mongoosastic, can not createMappingmongoosastic,无法创建映射
【发布时间】:2018-07-19 11:48:11
【问题描述】:

我已经安装了 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 
});

我该如何解决?

【问题讨论】:

    标签: node.js mongodb elasticsearch mongoosastic


    【解决方案1】:

    如果您使用的是 Elasticsearch 6.x,那么这是由于默认将“字符串”类型转换为“文本”的不兼容问题。

    看看这篇关于 ES Strings are Dead... 的帖子,最后他们写了以下内容:

    ...也就是说,您仍然应该考虑升级它们,因为我们计划在发布 Elasticsearch 6.0 时移除这个向后兼容层。

    我已将 a pull request 提交给 mongoosastic github repo 以解决此问题以及与此库的其他一系列不兼容问题。如果你仍然想使用这个库,你可以添加我的克隆仓库,直到他们修复上游的问题。

    带有修复程序的 Github 存储库是 https://github.com/avadhpatel/mongoosastic

    【讨论】:

    • 非常感谢,现在已修复
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-14
    • 1970-01-01
    相关资源
    最近更新 更多