Logstash写入Elasticsearch发生的metadata通配异常问题

简介: Logstash写入Elasticsearch发生的metadata通配异常问题

我们在做Elasticsearch数据迁移的时候,往往因为数据量太多,有大量索引需要迁移,所以在logstash里配置的索引名多为模糊匹配,但是在实际使用中,却会遇到一些问题。

说明

  • 系统环境说明

Linux环境:CentOS Linux release 7.2 (Final)

Elasticsearch:7.10.1

Logstash:7.10.2

Java:1.8.0_181

背景

我们在做Elasticsearch数据迁移的时候,往往因为数据量太多,有大量索引需要迁移,所以在logstash里配置的索引名多为模糊匹配,但是在实际使用中,却会遇到一些问题。

问题及解决方案

问题一:不允许使用通配符

[2021-09-15T13:36:34,723][INFO ][logstash.outputs.elasticsearch] retrying failed action with response code: 403 ({"type"=>"security_exception", "reason"=>"action [indices:admin/create] is unauthorized for user [elastic]", "caused_by"=>{"type"=>"illegal_state_exception", "reason"=>"There are no external requests known to support wildcards that don't support replacing their indices"}})
[2021-09-15T13:36:34,723][INFO ][logstash.outputs.elasticsearch] retrying failed action with response code: 403 ({"type"=>"security_exception", "reason"=>"action [indices:admin/create] is unauthorized for user [elastic]", "caused_by"=>{"type"=>"illegal_state_exception", "reason"=>"There are no external requests known to support wildcards that don't support replacing their indices"}})
[2021-09-15T13:36:34,723][INFO ][logstash.outputs.elasticsearch] retrying failed action with response code: 403 ({"type"=>"security_exception", "reason"=>"action [indices:admin/create] is unauthorized for user [elastic]", "caused_by"=>{"type"=>"illegal_state_exception", "reason"=>"There are no external requests known to support wildcards that don't support replacing their indices"}})
[2021-09-15T13:36:34,724][INFO ][logstash.outputs.elasticsearch] retrying failed action with response code: 403 ({"type"=>"security_exception", "reason"=>"action [indices:admin/create] is unauthorized for user [elastic]", "caused_by"=>{"type"=>"illegal_state_exception", "reason"=>"There are no external requests known to support wildcards that don't support replacing their indices"}})
[2021-09-15T13:36:34,724][INFO ][logstash.outputs.elasticsearch] retrying failed action with response code: 403 ({"type"=>"security_exception", "reason"=>"action [indices:admin/create] is unauthorized for user [elastic]", "caused_by"=>{"type"=>"illegal_state_exception", "reason"=>"There are no external requests known to support wildcards that don't support replacing their indices"}})
[2021-09-15T13:36:34,724][INFO ][logstash.outputs.elasticsearch] retrying failed action with response code: 403 ({"type"=>"security_exception", "reason"=>"action [indices:admin/create] is unauthorized for user [elastic]", "caused_by"=>{"type"=>"illegal_state_exception", "reason"=>"There are no external requests known to support wildcards that don't support replacing their indices"}})
[2021-09-15T13:36:34,724][INFO ][logstash.outputs.elasticsearch] Retrying individual bulk actions that failed or were rejected by the previous bulk request. {:count=>125}

解决方案

这个报错是因为output段index => 不允许为*,这里需要将output段里的index修改为

index => "%{[@metadata][_index]}"

问题二:目标集群自动创建出名称为@metadata的索引

这个问题是因为input段没有显式指定docinfo为true,其含义是开启文档信息,其中包含了索引名称、类型、文档id这些信息。如果没有显式指定为true,那这个值默认false,会导致output段拿不到metadata的相关值,直接导致%{[@metadata][_index]}等变量的异常。

截图来自 —— plugins inputs elasticsearch docinfo

解决方案

正确demo示范:

input {
   
   elasticsearch {
   
       hosts => "1.1.1.1:9200"
       index => "*"
       docinfo => true
       size => 5000
       scroll => "5m"
     }
}
output {
   
   elasticsearch {
   
       hosts => ["http://2.2.2.2:9200"]
       user => "elastic"
       password => "your_password"
       index => "%{[@metadata][_index]}"
       document_type => "%{[@metadata][_type]}"
       document_id => "%{[@metadata][_id]}"
   }
}

问题三:未知索引名称导致logstash写入报不允许通配的问题

在另一种场景中,我们没有使用metadata的docinfo信息,但是还是会拿到不允许通配的报错:

[2021-01-04T16:09:46,517][INFO ][logstash.outputs.elasticsearch][main][15029ec90b014722fb1e21a3d9bea5122d0776b75db4d73c2b75c774c6d36eef] retrying failed action with response code: 403 ({"type"=>"security_exception", "reason"=>"action [indices:admin/create] is unauthorized for user [elastic]", "caused_by"=>{"type"=>"illegal_state_exception", "reason"=>"There are no external requests known to support wildcards that don't support replacing their indices"}})
[2021-01-04T16:09:46,518][INFO ][logstash.outputs.elasticsearch][main][15029ec90b014722fb1e21a3d9bea5122d0776b75db4d73c2b75c774c6d36eef] Retrying individual bulk actions that failed or were rejected by the previous bulk request. {:count=>3}
[2021-01-04T16:10:47,124][INFO ][logstash.outputs.elasticsearch][main][15029ec90b014722fb1e21a3d9bea5122d0776b75db4d73c2b75c774c6d36eef] retrying failed action with response code: 403 ({"type"=>"security_exception", "reason"=>"action [indices:admin/create] is unauthorized for user [elastic]", "caused_by"=>{"type"=>"illegal_state_exception", "reason"=>"There are no external requests known to support wildcards that don't support replacing their indices"}})
[2021-01-04T16:10:47,125][INFO ][logstash.outputs.elasticsearch][main][15029ec90b014722fb1e21a3d9bea5122d0776b75db4d73c2b75c774c6d36eef] Retrying individual bulk actions that failed or were rejected by the previous bulk request. {:count=>1}

解决方案

遇到的问题很奇怪,经过一番检查,我们在logstash配置的output段发现了端倪:

output {
   
        stdout {
   codec => rubydebug}
    if [rtype] {
   
            elasticsearch {
   
                    #index => "%{rtype}_%{+YYYY.MM.dd}"
                    index => "%{rtype}_%{date_index}"
                    hosts => ["http://2.2.2.2:9200"]
                    user => "elastic"
                    password => "your_password"
            }
    }
}

这里可以明确地看到,if判断条件过于简单,只要字段存在就进行写入,并且还以条件为索引名。这个显然不合理,这种情况去查看索引列表,一定可以发现很多不符合预期的索引名称,包括通配符的存在,所以这里就需要进行优化。

优化方案:

  • 尽量避免以条件为索引名,容易发生未知的问题;
  • 如果索引名称一定要是条件,则需要严格判断字段内容,控制索引名在预期内,并且要判断出else的未知字符串,否则将发生难以接受的后果。
目录
相关文章
|
1月前
|
人工智能 移动开发 自然语言处理
千问办公QwenWork指南:介绍、能力、官网、使用、版本及价格说明
千问办公(QwenWork)是阿里巴巴推出的一站式AI Agent生产力平台,支持“对话即交付”:用户用自然语言描述需求,即可自动生成PPT、Excel、网页、报告等可落地成果;深度集成钉钉,覆盖多端,赋能个人与企业高效办公。阿里千问办公QwenWork官网:https://t.aliyun.com/U/0VCTGt
|
1月前
|
监控 Java 关系型数据库
SpringCloud Alibaba完整使用
SpringCloud Alibaba 微服务全栈实战教程,从零带你搭建 Nacos 注册配置中心、Gateway 网关、Sentinel 限流熔断、Seata 分布式事务、OpenFeign 远程调用等完整微服务组件。配套全套视频教程 + 保姆级搭建文档,手把手教你跑通微服务项目,适合在校生、转行及 1-3 年后端开发者学习练手、简历加分,文末可领学习资料与技术交流群。
|
1月前
|
人工智能 安全 测试技术
Agent 也要被测试:如何评测一个 Agent 的 Skills?
本文探讨AI Agent中Skill评测的核心挑战与实践方法:指出Skill失效常表现为“行为漂移”而非报错;提出三层评测体系——静态校验(结构/安全/去重)、轨迹评估(步骤与序列合理性)、端到端配对测试(A/B对照测Skill Lift);强调需兼顾结果有效性、路径合理性、副作用与退化风险,并倡导将评测嵌入CI门禁,用最小可行方案启动防退化机制。
|
1月前
|
存储 缓存 安全
阿里云2核2G99元和2核4G199元云服务器活动,最长4年续费周期,个人建站首选
本文梳理阿里云99元经济型e实例(2核2G/3M/40G)与199元u1实例(2核4G/5M/80G)的适用场景、参与资格、续费规则与成本结构。二者面向个人开发者、学生、小微团队等入门上云用户,在活动延期至2029年3月31日的规则下,符合条件者经多次续费可接近4年低价持有。文章提醒用户关注配置一致性、续费窗口、保有数量与截止时间,并按项目生命周期选型,做好域名、备案、存储与备份等完整成本规划。
|
1月前
|
缓存 前端开发 程序员
DeepSeek-V4.1-Flash-1017 上手实测:3D 直出,效果到底如何
DeepSeek-V4.1-Flash-1017 上手实测:3D 飞行特斯拉、千里江山、折叠掌机一次直出,跑分 77%、最高档单任务 1.3 元
DeepSeek-V4.1-Flash-1017 上手实测:3D 直出,效果到底如何
|
1月前
|
弹性计算 网络安全 API
阿里云服务器199元1年购买与使用常见问题:2核4G5M带宽,续费同价,企业用户专享
阿里云企业专享轻量服务器:2核4G+5M带宽,仅199元/年!需企业实名认证,支持续费同价与专票。5M带宽(0.625MB/s)适合博客、API、管理系统等,搭配CDN更佳。含安全组配置、宝塔/Docker一键部署、快照备份及免费SSL指南,是初创团队高性价比之选。(239字)
240 0
|
1月前
|
人工智能 IDE 安全
开发者手册|阿里云Qoder CN指南:产品能力、用途、订阅收费全解析,免费300 Credits
Qoder CN是阿里云推出的国产AI智能体产品系列(原通义灵码),专注软件开发与办公场景。含IDE插件、CLI工具、Cloud Agents平台及数字员工等,支持自主编程、深度IDE集成与本地安全运行。注册即赠800次3.8-Max调用,个人版59元/月起。阿里云Qoder CN官网:https://t.aliyun.com/U/fEiOLV
293 0
|
1月前
|
弹性计算 人工智能 安全
从 0 到 1 玩转 DeepSeek Harness 保姆级教程:阿里云计算巢 + ECS 一键部署,含百炼 API Key 配置与代码命令+避坑教程
综合来看,基于阿里云计算巢 + ECS 搭建 DeepSeek Harness 智能体平台,门槛低、上手快。先获取百炼 API Key(注意地域隔离与密钥保存),再通过计算巢一键部署,最后通过 Nginx 反向代理与计算巢安全代理安全访问 Web UI,即可投入使用。开发者也可以不依赖计算巢,直接使用 npx 命令或源码安装方式在本地或 ECS 上运行。部署时重点关注 API Key 只显示一次、地域不能混用、13080 与 3080 端口分工等要点,即可快速搭建一套功能完整、安全可控、可灵活扩展的 AI Agent 平台,支撑各类智能体应用的开发与落地。
225 0
|
1月前
|
人工智能 API 调度
阿里云百炼 Token Plan 深度解析:统一额度计费,底层架构与 API 接入指南
Token Plan通过统一Credits抵扣、多协议网关适配、多模型资源池调度的架构,解决了传统多模型开发中计费复杂、工具集成繁琐、账单管理困难的痛点。一份订阅,即可调用文本、图像、视频、语音等多模态模型,搭配联网检索、代码解释器等Agent工具,并且兼容市面上主流AI编程客户端,大幅降低AI应用开发成本。
234 0
|
1月前
|
存储 弹性计算 人工智能
阿里云2026年新用户特惠有哪些?阿里云四大权益参与时间、入口一次说全
新人特惠每个账号限购一次,同一实名主体只能享受一次秒杀资格,不要注册多账号反复薅,会被关联识别;代金券和免费额度都有有效期,领取后要在有效期内使用,部分券只支持新购不支持续费;特价实例分地域库存,38元档常售罄,下单前确认目标地域有货;免费试用结束后再下单仍可享受新用户优惠价,可以放心先试后买。把技术约束放在价格之前,先定负载、再匹配配置、最后在活动窗口内下单,才能把这波新人红利吃到最足。
419 0

热门文章

最新文章