gpt4 book ai didi

elasticsearch - 如何在 Elasticsearch 重新索引无痛脚本中生成 UUID

转载 作者:行者123 更新时间:2023-12-02 22:28:15 26 4
gpt4 key购买 nike

我正在尝试使用 reindex api 创建一组文档的副本。文档的字段之一 (uuid) 是 UUID。我需要复制的文档在 uuid 字段中具有新的 UUID。

根据 [1] 和 [2],方法 java.util.UUID.randomUUID() 未列入白名单以用于无痛脚本。

问题:

1) 如何轻松生成 UUID?

2) 为什么 UUID.randomUUID() 被认为是不安全的操作?或者它只是一个疏忽,它没有被列入白名单?

3) 如何在 "reindex" 上下文中将 UUID.randomUUID() 列入白名单?我尝试基于 [3] 中的示例构建自己的 elasticsearch 无痛扩展/插件来执行此操作。问题是它只适用于 "SearchScript" 上下文。似乎没有等效的 "ReindexContext"

这是我正在尝试的简化版本:

curl -X POST "localhost:9200/_reindex?pretty" -H 'Content-Type: application/json' -d'
{
"source": {
"index": "product1"
},
"dest": {
"index": "product2"
},
"script": {
"source": "ctx._source.uuid = java.util.UUID.randomUUID().toString()",
"lang": "painless"
}
}
'

这会产生以下错误:

{
"error" : {
"root_cause" : [
{
"type" : "script_exception",
"reason" : "compile error",
"script_stack" : [
"... rce.uuid = java.util.UUID.randomUUID().toString()",
" ^---- HERE"
],
"script" : "ctx._source.uuid = java.util.UUID.randomUUID().toString()",
"lang" : "painless"
}
],
"type" : "script_exception",
"reason" : "compile error",
"script_stack" : [
"... rce.uuid = java.util.UUID.randomUUID().toString()",
" ^---- HERE"
],
"script" : "ctx._source.uuid = java.util.UUID.randomUUID().toString()",
"lang" : "painless",
"caused_by" : {
"type" : "illegal_argument_exception",
"reason" : "method [java.util.UUID, randomUUID/0] not found"
}
},
"status" : 500
}

我知道我的方法是有效的,并且上述是一个无痛的白名单问题,因为当我尝试不同的方法 (fromString()) 时,我没有得到任何错误:

curl -X POST "localhost:9200/_reindex?pretty" -H 'Content-Type: application/json' -d'
{
"source": {
"index": "product1"
},
"dest": {
"index": "product2"
},
"script": {
"source": "ctx._source.uuid = java.util.UUID.fromString(\u0027ad139caa-5b54-4179-b812-5015daecad1e\u0027).toString()",
"lang": "painless"
}
}
'

引用资料:

[1] - https://discuss.elastic.co/t/generate-a-uuid-using-randomuuid-in-painless/144354/3

[2] - https://www.elastic.co/guide/en/elasticsearch/painless/6.6/painless-api-reference.html

[3] - https://github.com/elastic/elasticsearch/tree/v6.6.0/plugins/examples/painless-whitelist

其他注意事项:

最佳答案

我解决此问题的功能请求已在此处接受并实现:https://github.com/elastic/elasticsearch/issues/39080

关于elasticsearch - 如何在 Elasticsearch 重新索引无痛脚本中生成 UUID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54682324/

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