脚本字段正则表达式不适用于多个节点

Scripted field regex not working on multiple node

我想创建一个基于 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。有人可以向我解释一下吗?非常感谢

如错误所述,

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.

您需要设置

script.painless.regex.enabled: true

在您的 elasticsearch.yml 字段中并重新启动 ES。