elasticsearch导入数据

logstash

  1. 下载对应版本的logstash

wget https://artifacts.elastic.co/downloads/logstash/logstash-7.1.1.tar.gz

  1. 下载测试数据

    下载最MovieLens最小测试数据集:https://grouplens.org/datasets/movielens/

  2. 配置文件logstash.conf

input {
  file {
    path => "/root/movies.csv"  //修改为自己的文件配置目录
    start_position => "beginning"
    sincedb_path => "/dev/null"
  }
}
filter {
  csv {
    separator => ","
    columns => ["id","content","genre"]
  }

  mutate {
    split => { "genre" => "|" }
    remove_field => ["path", "host","@timestamp","message"]
  }

  mutate {

    split => ["content", "("]
    add_field => { "title" => "%{[content][0]}"}
    add_field => { "year" => "%{[content][1]}"}
  }

  mutate {
    convert => {
      "year" => "integer"
    }
    strip => ["title"]
    remove_field => ["path", "host","@timestamp","message","content"]
  }

}
output {
   elasticsearch {
     hosts => "http://es:9200"   //修改为自己的es地址
     index => "movies"
     document_id => "%{id}"
   }
  stdout {}
}
  1. 执行命令sudo bin/logstash -f /YOUR_PATH_of_logstash.conf

文章作者: 凌云
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 凌云 !
  目录