Reputation: 895
The server is started on port 3000.
Error creating mapping[mapper_parsing_exception] No handler for type [string] declared on field [category] :: {"path":"/products/_mapping/product","query":{},"body":"{\"product\":{\"properties\":{\"category\":{\"type\":\"string\"},\"name\":{\"type\":\"string\"},\"price\":{\"type\":\"double\"},\"image\":{\"type\":\"string\"}}}}","statusCode":400,"response":"{\"error\":{\"root_cause\":[{\"type\":\"mapper_parsing_exception\",\"reason\":\"No handler for type [string] declared on field [category]\"}],\"type\":\"mapper_parsing_exception\",\"reason\":\"No handler for type [string] declared on field [category]\"},\"status\":400}"}
connected to database
Indexed 120 documents
//code
Product.createMapping(function(err, mapping){
if(err){
console.log("Error creating mapping"+ err);
}else{
console.log("Mapping Cretaed");
console.log(mapping);
}
});
var stream = Product.synchronize();
var count = 0;
stream.on('data', function(){
count++;
});
stream.on('close', function(){
console.log("Indexed " + count + "documents");
});
stream.on('error', function(err){
console.log(err);
});
New code added to explain what product is
var mongoose = require("mongoose");
var Schema = mongoose.Schema;
var mongoosastic = require("mongoosastic");
//Schema
var ProductSchema = new Schema({
category : {
type : Schema.Types.ObjectId,
ref : 'Category'
},
name : String,
price : Number,
image : String
});
ProductSchema.plugin(mongoosastic, {
hosts : [
'localhost:9200'
]
})
module.exports = mongoose.model('Product', ProductSchema);
Upvotes: 0
Views: 4145
Reputation: 217304
In the mapping you're trying to create, you have a type string
which has been deprecated in ES 5.x. You need to use text
or keyword
instead.
Your mapping should look like this instead:
{
"product": {
"properties": {
"category": {
"type": "keyword"
},
"name": {
"type": "text"
},
"price": {
"type": "double"
},
"image": {
"type": "text"
}
}
}
}
UPDATE:
The issue comes from the fact that as of June 26th, 2018, mongoosastic 4.4.1 doesn't support ES5. One workaround is to modify your mongo schema like this
category: {
type: String,
es_type: 'keyword'
}
price: {
type: Number,
es_type: 'double'
}
name: {
type: String,
es_type: 'text'
}
image: {
type: String,
es_type: 'text'
}
Upvotes: 1