【问题标题】:Set Logstash Date Filter from current date to last 3 days将 Logstash 日期过滤器从当前日期设置为过去 3 天
【发布时间】:2018-11-28 08:50:06
【问题描述】:

我在一个索引中有完整的数据库,我需要创建或获取 3 天的记录并以 CSV 格式存储。目标是每天需要 3 天的回溯记录并存储在 CSV 文件中。如何仅使用 logstash.config 设置从当前日期开始到最近 3 天?

我的 Logstash 配置文件

input {
elasticsearch {
     hosts => "**Endpoint URL**"
     index => "**Index NAME**"
     user => "***"
     password => "***"
     query => '{ "query": { "query_string": { "query": "*" } } }'
    }
}
filter {
csv {
separator => ","
autodetect_column_names => true
autogenerate_column_names => true
}
}  
output {
     stdout {  
     codec => json_lines
            }
     csv {
     fields => []
     path => "C:/ELK_csv/**cvs_File_Name**.csv"     
  }
  }

需要添加日期过滤范围

{"query":{"bool":{"must":[{"range":{"createddate":{"gte":"","lt":""}}}],"must_not":[],"should":[]}},"from":0,"size":5000,"sort":[],"aggs":{}}

gte 从当前日期开始,持续 3 天。

【问题讨论】:

    标签: elastic-stack logstash-configuration


    【解决方案1】:

    工作 Logstash.config 文件代码

    input {
    elasticsearch {
         hosts => "**ELK ENDPOINT URL**"
         index => "**INDEX NAME**"
         user => "***"
         password => "***"
         query => '{ "query":{"bool":{"must":[{"range":{"createddate":{"gt":"now-3d/d","lte":"now/d"}}}],"must_not":[],"should":[]}},"from":0,"size":10000,"sort":[],"aggs":{} }'
        }
    }
    filter {
    csv {
    separator => ","
    autodetect_column_names => true
    autogenerate_column_names => true
    }
    }  
    output {
         stdout {  
         codec => json_lines
                }
         csv {
         fields => [**FIELDS NAMES**]
         path => "C:/ELK6.4.2/logstash-6.4.2/bin/tmp/**CSV_3days**.csv"     
      }
      }
    

    【讨论】:

      猜你喜欢
      • 2019-11-28
      • 2014-10-20
      • 1970-01-01
      • 2016-05-17
      • 2016-05-21
      • 2018-06-11
      • 2013-03-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多