zoukankan      html  css  js  c++  java
  • logstash导出ElasticSearch数据到CSV及同步两套ES的数据研究

    一、安装

    参考:https://www.cnblogs.com/cpy-devops/p/9287531.html

    首先保证系统安装了java 1.8以上版本

    tar –zxvf /home/logstash-7.7.0.tar.gz -C /usr/local

    进入/usr/local/logstash-7.7.0/bin目录下

    二、配置文件

    创建文件 convert_csv.conf

    input{
          elasticsearch {
             hosts => ["127.0.0.1:9200"]    #要导出来的es服务器的地址
             index => "es的数据index值"      
         }
    }
    output{
        file {

         filed => [””,””,””]    #filed字段选择,如下图展示_source中的信息,带有下划线的字段不需要选择
    #path为指定文件路径
          path => "/home/csv.csv"
        }

    }


    image

    三、执行

    ./logstash -f convert_csv.conf

    同步两套ES数据

    只需要将上述output修改对应的es的output即可

    output {
    
        elasticsearch {
            #全文检索服务
            hosts => "localhost:9200"
            #索引(数据库)
            index => "zl_dev"
            #类型(数据库表)
            document_type => "%{type}"
            #主键(防止重复)
            document_id => "%{id}"
        }
    }


    实时同步es数据

    官方帮助文档:https://www.elastic.co/guide/en/logstash/current/plugins-inputs-elasticsearch.html

    需要插件 Elasticsearch input plugin

        input {
          # Read all documents from Elasticsearch matching the given query
          elasticsearch {
            hosts => "localhost"
            query => '{ "query": { "match": { "statuscode": 200 } }, "sort": [ "_doc" ] }'
          }
        }

    计划增加 输入读取选项 schedule index 

    input {
          # Read all documents from Elasticsearch matching the given query
          elasticsearch {
            hosts => "localhost"
            index => "按照时间索引传入"
            query => '{ "query": { "match": { "statuscode": 200 } }, "sort": [ "_doc" ] }'
            schedule =>  "* * 1 * *" #每天凌晨1点执行  #任务调度 (分、时、天、月、年,全部为*默认含义为每分钟都更新)
    
          }
        }

    输出与上述输出到es一致即可









  • 相关阅读:
    robots.txt
    procdump和mimikatz工具配合破解windows账户口令
    通过vbs脚本控制方向盘按键
    批处理删除文件或文件夹代码
    彩色线条雨特效html代码
    secureCRT
    chrome 更新flash插件
    python命令行下安装redis客户端
    FastJson使用
    Redis 学习(二)
  • 原文地址:https://www.cnblogs.com/wang3680/p/13130459.html
Copyright © 2011-2022 走看看