regex - 脚本字段正则表达式不适用于多个节点
问题描述
我想创建一个基于 cs_uri_query 列的脚本字段。当我创建这个正则表达式公式时,我一直在使用 elasticsearch 7.5 直到 7.6。它在索引 A 的脚本字段中运行良好。现在我已经将我的 elasticsearch 升级到 7.7,并且我已经将索引 B 摄取到我的 elasticsearch。索引 B 和索引 A 具有相同的格式(列中的所有内容都相同)所以我想使用相同的正则表达式公式。但不幸的是,当我将索引 A 脚本字段复制到索引 B 中时。
它在索引 B 上返回此错误
{
"root_cause": [
{
"type": "script_exception",
"reason": "compile error",
"script_stack": [
"... = 0) return '';\r\ndef m = /(...(?=&custid))/.matche ...",
" ^---- HERE"
],
"script": "if (doc['cs_uri_query.keyword'].size() == 0) return '';\r\ndef m = /(...(?=&custid))/.matcher(doc['cs_uri_query.keyword'].value);\r\nif(m.find () )\r\n{return m.group(1) } \r\nelse { return \"No ID\" }",
"lang": "painless",
"position": {
"offset": 65,
"start": 40,
"end": 90
}
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "janmei",
"node": "KVuYPKPBRIO-mIQu0lS3LQ",
"reason": {
"type": "script_exception",
"reason": "compile error",
"script_stack": [
"... = 0) return '';\r\ndef m = /(...(?=&custid))/.matche ...",
" ^---- HERE"
],
"script": "if (doc['cs_uri_query.keyword'].size() == 0) return '';\r\ndef m = /(...(?=&custid))/.matcher(doc['cs_uri_query.keyword'].value);\r\nif(m.find () )\r\n{return m.group(1) } \r\nelse { return \"No ID\" }",
"lang": "painless",
"position": {
"offset": 65,
"start": 40,
"end": 90
},
"caused_by": {
"type": "illegal_state_exception",
"reason": "Regexes are disabled. Set [script.painless.regex.enabled] to [true] in elasticsearch.yaml to allow them. Be careful though, regexes break out of Painless's protection against deep recursion and long loops."
}
}
}
]
}
样本
id=000&custid=77777777&email=email@gmail.com
脚本字段
if (doc['cs_uri_query.keyword'].size() == 0) return '';
def m = /(...(?=&custid))/.matcher(doc['cs_uri_query.keyword'].value);
if(m.find () )
{return m.group(1) }
else { return "No ID" }
我将完全相同的脚本从索引 A 复制到索引 B。有人可以向我解释一下吗?非常感谢
解决方案
正如错误所述,
正则表达式被禁用。在 elasticsearch.yaml 中将 [script.painless.regex.enabled] 设置为 [true] 以允许它们。不过要小心,正则表达式会突破 Painless 对深度递归和长循环的保护。
你需要设置
script.painless.regex.enabled: true
在您的elasticsearch.yml
字段中并重新启动 ES。
推荐阅读
- python - to_numeric 返回浮点数 - 熊猫中的 astype 函数不起作用
- spring-data-mongodb - 为什么MongoDB聚合被Spring Data以错误的方式重写?
- node.js - 如何使用 sendgrid 模板从 node.js 发送 Google 日历邀请?
- typescript - 为什么函数需要两个参数,如果它已经在一个对象中?
- javascript - 在 axios 之后使用值的问题
- c# - 从父级而不是实体框架中的整个对象获取某个子属性
- python - 将字符串中的运算符插入表达式字符串
- node.js - 如何使用 NODE.JS 工具编辑 JSON 文件
- html - 在 Razor 页面中添加动态 html 属性会中断自动绑定
- node.js - 使用快速后端将 React SPA 中的图像保存在 S3 中