接上篇:Kibana 7.x 的安裝與界面預覽(阿里雲Ubuntu)html
# 內網,私有地址 172.內.內.內 # 外網,公有地址 112.外.外.外
~$ sudo apt install default-jdk ~$ java -version openjdk version "11.0.3" 2019-04-16 OpenJDK Runtime Environment (build 11.0.3+7-Ubuntu-1ubuntu218.04.1) OpenJDK 64-Bit Server VM (build 11.0.3+7-Ubuntu-1ubuntu218.04.1, mixed mode, sharing)
wget https://artifacts.elastic.co/downloads/logstash/logstash-7.2.0.tar.gz
tar -zxf logstash-7.2.0.tar.gz
cd logstash-7.2.0/
wget http://files.grouplens.org/datasets/movielens/ml-latest-small.zip
unzip ml-latest-small.zip
input { file { path => "/home/walker/es/ml-latest-small/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][2]}"} } mutate { convert => { "year" => "integer" } strip => ["title"] remove_field => ["path", "host","@timestamp","message","content"] } } output { elasticsearch { hosts => "http://172.18.193.52:9200" index => "movies" document_id => "%{id}" } stdout {} }
# 我的路徑有所不一樣 ./bin/logstash -f /home/walker/es/ml-latest-small/logstash.conf
# 查看數據總量 GET /movies/_count # 控制檯輸出 { "count" : 9743, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 } }
# 查看 id 爲 1 的數據 GET /movies/_doc/1 # 控制檯輸出 { "_index" : "movies", "_type" : "_doc", "_id" : "1", "_version" : 1, "_seq_no" : 121, "_primary_term" : 1, "found" : true, "_source" : { "@version" : "1", "genre" : [ "Adventure", "Animation", "Children", "Comedy", "Fantasy" ], "year" : 1995, "id" : "1", "title" : "Toy Story" } }
# 刪除命令 DELETE /movies # 控制檯輸出 { "acknowledged" : true }
$ tree /home/walker/es/ -L 2 /home/walker/es/ ├── elasticsearch-7.2.0 │ ├── bin │ ├── config │ ├── data │ ├── jdk │ ├── lib │ ├── LICENSE.txt │ ├── logs │ ├── modules │ ├── NOTICE.txt │ ├── plugins │ └── README.textile ├── elasticsearch-7.2.0-linux-x86_64.tar.gz ├── kibana-7.2.0-linux-x86_64 │ ├── bin │ ├── built_assets │ ├── config │ ├── data │ ├── LICENSE.txt │ ├── node │ ├── node_modules │ ├── NOTICE.txt │ ├── optimize │ ├── package.json │ ├── plugins │ ├── README.txt │ ├── src │ ├── target │ ├── webpackShims │ └── x-pack ├── kibana-7.2.0-linux-x86_64.tar.gz ├── logstash-7.2.0 │ ├── bin │ ├── config │ ├── CONTRIBUTORS │ ├── data │ ├── Gemfile │ ├── Gemfile.lock │ ├── lib │ ├── LICENSE.txt │ ├── logs │ ├── logstash-core │ ├── logstash-core-plugin-api │ ├── modules │ ├── NOTICE.TXT │ ├── tools │ ├── vendor │ └── x-pack ├── logstash-7.2.0.tar.gz ├── ml-latest-small │ ├── links.csv │ ├── logstash.conf │ ├── movies.csv │ ├── ratings.csv │ ├── README.txt │ └── tags.csv └── ml-latest-small.zip
本文是阮一鳴《 Elasticsearch核心技術與實戰》的學習筆記。