elasticsearch通過logstash去重數據


下載與es對應版本的logstash

下載地址:https://artifacts.elastic.co/downloads/logstash/logstash-6.7.1.tar.gz

一、去重原理

通過logstash將需要去重的索引導入新的索引,導入過程中為每個文檔指定唯一id,文檔數據相同時會自動過濾。

二、去重步驟

1.解壓logstash-6.7.1.tar.gz

tar -zxvf logstash-6.7.1.tar.gz

2.寫conf文件

input {
  elasticsearch {
    hosts => "192.168.56.6" #es主節點ip
    index => "t_people_latlng20191101" #需要去重的索引
    query => '{ "sort": [ "_doc" ] }'
  }
}

filter {
    mutate {
        remove_field => ["@timestamp", "@version"] #去除多余字段
    }
    fingerprint {
        source => ["deviceid", "utc"]  #根據哪些字段去重,此處根據id和時間字段
        target => "[@metadata][fingerprint]"
        method => "MURMUR3"  #設置唯一id的方法
        concatenate_sources => true  #將多個字段拼接為唯一id
    }
}
output {
    stdout { codec => dots }  #輸出打印
    elasticsearch {
        hosts => "192.168.56.6" #指定的es主節點ip
        index => "newt_people_latlng20191101"  #新的索引
        document_id => "%{[@metadata][fingerprint]}"
    }
}

3.執行conf文件

cd logstash-6.7.1
./bin/logstash -f ship20201103.conf

4.執行多個conf文件

#!/bin/bash


#要執行的conf文件目錄
cd "/data/es/logstash-6.7.1/conf"
dir="/data/es/logstash-6.7.1/conf"
files=`find . -name "ship*"`
for file in $files
do
   #執行多個conf,需要分別指定不同的data路徑
    /data/es/logstash-6.7.1/bin/logstash -f $dir/$file --path.data  $dir/data/${file:2:12}
done

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM