gpt4 book ai didi

elasticsearch - 长类型的 Elasticsearch 无痛脚本问题

转载 作者:行者123 更新时间:2023-12-02 23:25:34 25 4
gpt4 key购买 nike

I am currently using Elastic search 5.2 and trying to perform upsert operation using the following rest api:


  • http://ip:9200/indexname/typename/id/_update

    杰森有效载荷:
    {
    "script" : {
    "inline": "ctx._source.size +=params.size",
    "lang": "painless",
    "params" :{
    "size" : 14889114000
    }
    },
    "upsert" : {
    "size" : 1488911400
    }


  • 此api执行以下操作:

    1.)如果在 flex 搜索中未找到索引,则使用upsert字段内提供的json创建一个索引。
    2.)如果索引存在,则它将通过运行文档中提供的简单脚本来执行部分更新。

    问题:我为计数器创建了 flex 搜索索引映射,直到计数器值在整数范围内为止,该更新工作正常。(即)2,147,483,647超出此值,它将溢出并变为负值,以防出现预期值它是正的long值(因为相应的索引图很长)。有没有办法使用无痛脚本来解决此int溢出问题?

    最佳答案

    您只需要稍微修改一下脚本,而无需使用+=运算符。如果您将脚本修改为ctx._source.size = ctx._source.size + params.size而不是ctx._source.size += params.size,那么它将按预期工作:

    POST indexname/typename/id/_update
    {
    "script" : {
    "inline": "ctx._source.size = ctx._source.size + params.size",
    "lang": "painless",
    "params" :{
    "size" : 14889114000
    }
    },
    "upsert" : {
    "size" : 1488911400
    }
    }

    首先,将使用 size: 1488911400对文档进行加衬,然后在第二次更新中,其将包含 size: 163780254001488911400 + 14889114000

    关于elasticsearch - 长类型的 Elasticsearch 无痛脚本问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43725530/

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