node.js - 如何整合Mongoosastic?
问题描述
完全陌生ELASTICSEARCH
我有一个mongoose schema
这样的定义
const newSchema = new mongoose.Schema({
name: String,
age: Number,
interests: [Objects],
});
newSchema.plugin(mongoosastic);
New = module.exports = mongoose.model('New', newSchema);
New.createMapping({
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0,
"analysis": {
"filter": {
"nGram_filter": {
"type": "nGram",
"min_gram": 2,
"max_gram": 20,
"token_chars": [
"letter",
"digit",
"punctuation",
"symbol"
]
}
},
"analyzer": {
"nGram_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase",
"asciifolding",
"nGram_filter"
]
},
"whitespace_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase",
"asciifolding"
]
}
}
}
},
"mappings": {
"new": {
"_all": {
"analyzer": "nGram_analyzer",
"search_analyzer": "whitespace_analyzer"
},
"properties": {
"name": {
"type": "string",
},
"age": {
"type": "string",
},
"interests": {
"type": "string",
},
}
}
}
}, function(err, mapping) {
if (err) {
console.log('error');
console.log(err);
} else {
console.log('mapping created!');
console.log(mapping);
}
});
当我运行上述项目时,我收到错误消息:
消息:'[mapper_parsing_exception] 没有在字段 [age] 上声明的类型 [string] 的处理程序'
我究竟做错了什么?我对弹性搜索完全陌生,mongoosastic。
我对elasticsearch一点都不懂,上面的createMapping
功能是从网上抄来的。
解决方案
推荐阅读
- mysql - 与另一列的所有元素相关的列中的值
- scala - 读取具有不同架构的 JSON 文件
- php - 在肥皂请求中发送更多功能
- vue.js - 为什么 prop 值会随着 vuejs3 中的数据变化而变化?
- c# - 正在创建并返回 FileContentResult,但没有下载文件
- javascript - MongoDB 自动将 < 替换为 <
- smartcontracts - 基板 - 尘土飞扬的网络 - reateType(Call):: findMetaCall: Unable to find Call
- ansible - 如何在剧本(yaml)中编写“echo”命令
- javascript - 无法使用 react-router-dom 链接对未安装的组件执行 React 状态更新
- python - Spark multicharacter delimiter write 写入数据中的不可打印字符