如何解决ElasticSearch、JavaScript 和传递整数值
我正在研究将 ElasticSearch 集成到使用 JavaScript 的 Parse Server 云代码中,并遵循文档和显式映射示例。我创建了索引,我想将字段映射为最小的整数 - 值将始终在 0…100 的范围内 - 因为文档声称这将有利于性能。举个例子:
PUT /profile/
{
"mappings": {
"properties": {
"ag": { "type": "byte" },"gn": { "type": "byte" },"d": { "type": "boolean" }
}
}
}
但是当我在 Cloud Code 中使用这个 JavaScript 客户端并想要传递数字值时,我收到一个错误。示例:
async function(profile,newDocument) { //PrsProfile,Bool
const result = await esClient.index({
id: profile.id,index: 'profile',type: ((newDocument == true) ? 'create' : 'index'),body: {
ag: profile.get("ag"),// <-- this is Number of value 36,but elastic expects byte type
gn: profile.get("gn"),// <-- this is Number of value 0,but elastic expects byte type
d: profile.get("d")
}
})
return (`Hello world + ${result}`);
错误:映射更新被主拒绝 java.lang.IllegalArgumentException: 映射器 [ag] 不能从 输入 [byte] 到 [long]
使用动态映射工作正常,因为 ElasticSearch 会自动映射它
无法使用 Cloud Code 函数 (JavaScript) 并在该正文标头中传递“字节”或“整数”类型,我是否正确?或者有没有办法传递Integer?
以这种方式通过 Int8Array 尝试也不行:
var ageIntArr = new Int8Array(1);
ageIntArr[0] = 30;
const result = await esClient.index({
id: profile.id,body: {
ag: ageIntArr[0]
}
})
谢谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。