📣 极限科技诚招搜索运维工程师(Elasticsearch/Easysearch)- 全职/北京 👉 : 立即申请加入

版本: 6.8-8.9

简要来说,当在 Elasticsearch 的跨域资源共享(CORS)设置中使用了无效的正则表达式(regex)时,就会出现此错误。错误信息表明在 ‘SETTING_CORS_ALLOW_ORIGIN’ 键中使用的正则表达式是不正确的。要解决此问题,你应该检查并修正正则表达式模式。确保它符合标准的正则表达式语法。同时,确保 ‘origin’ 变量被正确定义,并且不包含任何可能破坏正则表达式模式的字符。

日志上下文 #

日志 “[Bad regex in [” + SETTING_CORS_ALLOW_ORIGIN.getKey() + “]: [” + origin + “]” 的类名是 CorsHandler.java。我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入了解的人参考:

builder = CorsHandler.Config.Builder.forOrigins(RestUtils.corsSettingAsArray(origin));
 } else {
 builder = CorsHandler.Config.Builder.forPattern(p);
 }
 } catch (PatternSyntaxException e) {
 throw new SettingsException("Bad regex in [" + SETTING_CORS_ALLOW_ORIGIN.getKey() + "]: [" + origin + "]"; e);
 }
 }
 if (SETTING_CORS_ALLOW_CREDENTIALS.get(settings)) {
 builder.allowCredentials();
 }