微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ElasticSearch、JavaScript 和传递整数值

如何解决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 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?