Abdol Seed
Abdol Seed

Reputation: 1445

mongoosastic, can not createMapping

I have installed Elasticsearch and Kibana. I have an application using NOdejs and MongoDB. This is my schema config:

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);
  }
});

But I got this error:

Users.createMapping(function(err, mapping){
  ^
TypeError: Users.createMapping is not a function

I've also tried this but got same error:

Users.createMapping({
  "analysis" : {
  "analyzer":{
    "content":{
      "type":"custom",
        "tokenizer":"whitespace"
      }
    }
  }
},function(err, mapping){
  // do neat things here 
});

How can I fix it?

Upvotes: 1

Views: 1208

Answers (1)

AvadhP
AvadhP

Reputation: 1481

If you are using Elasticsearch 6.x then this is due to incompatibility issue of converting 'string' types to 'text' by default.

Take a look at this post on ES Strings are Dead... where at the end they wrote the following:

...That said, you should still look into upgrading them since we plan on removing this backward compatibility layer when we release Elasticsearch 6.0.

I've submitted a pull request to mongoosastic github repo to fix this and another bunch of incompatibility issues with this library. If you are still looking to use this library, you can add my clone repo with the fix until they fix the issues upstream.

Github repo with the fix is https://github.com/avadhpatel/mongoosastic

Upvotes: 1

Related Questions