Logstash年度索引查询未创建索引触发404告警求助
问题分析
当前核心问题是:filter阶段的elasticsearch查询插件在目标年度索引未创建时,会因404错误中断事件处理流程,导致事件无法到达output阶段执行索引创建操作。默认情况下,该插件遇到索引不存在的错误时会终止事件流转,而非继续执行后续逻辑。
解决方案
针对该问题,提供以下具体修复步骤:
1. 忽略索引不存在的错误
在filter的elasticsearch配置中添加ignore_missing_index => true参数,让插件在索引不存在时跳过错误,允许事件继续向后流转到output阶段,这样output就能自动触发索引创建。
2. 修正字段引用错误
配置中存在拼写错误:mutate { add_field => { "eventDate" => "%{[fecha]}" } }里的fecha应为date(前面date插件已将解析后的日期存入[date]字段),否则eventDate会是空值,导致重复检查的查询完全失效。
3. 简化重复检查逻辑(可选)
原有的eventDate转义冒号操作是多余的,date插件解析后的date字段已是标准日期格式,直接在查询中使用date:%{[date]}即可,无需额外转换。
修改后的完整配置示例
input { http_poller { urls => { air_quality => { url => "https://url_to_data" method => get headers => { Accept => "application/csv" } } } schedule => { every => "1h" } codec => line { charset => "UTF-8" } } } filter { # 跳过表头行 if [message] =~ /^Station/ { drop { } } # 解析CSV数据 csv { skip_header => "true" columns => ["station", "title", "latitude", "longitude", "date", "period", "SO2", "NO", "NO2", "CO", "PM10", "O3", "dd", "vv", "TMP", "HR", "PRB", "RS", "LL", "BEN", "TOL", "MXIL", "PM25"] separator => "," } # 解析日期字段 date { match => ["date", "yyyy-MM-dd"] timezone => "Europe/Madrid" target => "[date]" } # 检查重复事件(忽略索引不存在的错误) elasticsearch { hosts => "https://our_host_url" ca_file => "our_http_ca.crt" api_key => "our_API_KEY" index => "our-base-index-name-%{+YYYY}" query => "period:%{[period]} AND station:%{[station]} AND date:%{[date]}" ignore_missing_index => true } # 丢弃重复事件 if [@metadata][total_hits] != 0 { drop {} } # 重命名经纬度字段 mutate { rename => { "latitude" => "[situation][lat]" "longitude" => "[situation][lon]" } } } output { elasticsearch { hosts => "https://our_host_url" cacert => "our_http_ca.crt" api_key => "our_API_KEY" index => "our-base-index-name-%{+YYYY}" action => "create" template_name => "out-base-template-name" } }
补充说明
ignore_missing_index => true是核心修复配置,它让Logstash在查询不存在的索引时不终止事件流程,确保事件能到达output阶段完成索引创建。- 简化后的日期查询逻辑避免了无效字段转换,同时保证重复检查的准确性。
内容的提问来源于stack exchange,提问作者Bardo
相关产品推荐
相关产品推荐

