gpt4 book ai didi

node.js - ElasticSearch 上的 mapper_parsing_exception 错误

转载 作者:太空宇宙 更新时间:2023-11-04 00:08:35 33 4
gpt4 key购买 nike

服务器在端口 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}"}

连接到数据库

索引了 120 个文档

//代码

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

添加了新代码来解释产品是什么

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

最佳答案

在您尝试创建的映射中,有一个 string 类型,该类型已在 ES 5.x 中弃用。您需要使用文本关键字

您的映射应该如下所示:

{
"product": {
"properties": {
"category": {
"type": "keyword"
},
"name": {
"type": "text"
},
"price": {
"type": "double"
},
"image": {
"type": "text"
}
}
}
}

更新:

该问题来自于截至 2018 年 6 月 26 日,mongoosastic 4.4.1 doesn't support ES5 。一种解决方法是像这样修改您的 mongo 架构

category: { 
type: String,
es_type: 'keyword'
}
price: {
type: Number,
es_type: 'double'
}
name: {
type: String,
es_type: 'text'
}
image: {
type: String,
es_type: 'text'
}

关于node.js - ElasticSearch 上的 mapper_parsing_exception 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51010008/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com