天天看點

kibana 檢視有多少索引庫_幹貨 | Elasticsearch、Kibana資料導出實戰

1、問題引出

以下兩個導出問題來自Elastic中文社群。

問題1、kibana怎麼導出查詢資料?

問題2:elasticsearch資料導出

就像資料庫資料導出一樣,elasticsearch可以麼?

或者找到它磁盤上存放資料的位置,拷貝出來,放到另一個es伺服器上或者轉成自己要的資料格式?

實際業務實戰中,大家或多或少的都會遇到導入、導出問題。根據資料源的不同,基本可以借助:

  • 1、程式寫入
  • 2、資料同步

logstash/flume/cana/es_hadoopl等來實作關系型資料庫(如:Oracle、mysql)、非關系型資料庫(如:Mongo、Redis)、大資料(Hadoop、Spark、Hive)到Elasticsearch的寫入。

而資料的導出,一部分是業務場景需要,如:業務系統中支援檢索結果導出為CSV、Json格式等。

還有一部分是分析資料的需求:期望借助Kibana工具将儀表盤聚合結果導出、不需要借助程式盡快将滿足給定條件的結果資料導出等。

這些快速導出的需求,最好借助插件或者第三方工具實作。

本文将重點介紹Kibana/Elasticsearch高效導出的插件、工具集。

2、期望導出資料格式

一般期望導出:CSV、Json格式。

3、Kibana導出工具

3.1 Kibana 官方導出

步驟1:點選Kibana;步驟2:左側選擇資料,篩選字段;步驟3:右側點選:share->csv reports。步驟4:菜單欄:選擇Management->Reporting->下載下傳。

kibana 檢視有多少索引庫_幹貨 | Elasticsearch、Kibana資料導出實戰
kibana 檢視有多少索引庫_幹貨 | Elasticsearch、Kibana資料導出實戰

以上是kibana6.5.4的實操截圖。

其他常見報表資料導出:

kibana 檢視有多少索引庫_幹貨 | Elasticsearch、Kibana資料導出實戰

在Dashboard的右上角點選Inspect,再點選就可以導出對應可視化報表對應的資料。

3.2 資料透視表pivot-kibana

Kibana的資料透視表——使用Kibana UI中的任何其他工具一樣使用資料透視表可以極大地簡化資料工作。

Flexmonster Pivot可以交叉和快速地彙總業務資料并以交叉表格式顯示結果。

位址:https://github.com/flexmonster/pivot-kibana/

篩選資料效果如下:

kibana 檢視有多少索引庫_幹貨 | Elasticsearch、Kibana資料導出實戰

注意:建議7.X以上版本使用。低版本不支援。

4、Elasticsearch導出工具

4.1 es2csv

1、簡介:用Python編寫的指令行實用程式,用于以Lucene查詢文法或查詢DSL文法查詢Elasticsearch,并将結果作為文檔導出到CSV檔案中。es2csv 可以查詢多個索引中的批量文檔,并且隻擷取標明的字段,這可以縮短查詢執行時間。

2、位址:https://pypi.org/project/es2csv/

3、使用方法:

1es2csv -u 192.168.1.1:9200 -q '{"_source":{"excludes":["*gxn",,"*kex","vperxs","lpix"]},"query":{"term":{"this_topic":{"value":41}}}}' -r -i sogou_topic -o ~/export.csv           

4、使用效果:官方最新更新支援5.X版本,實際驗證6.X版本也可以使用,導出效率高。

kibana 檢視有多少索引庫_幹貨 | Elasticsearch、Kibana資料導出實戰

5、推薦指數:五星,

Elasticsearch導出CSV首選方案。

4.2 elasticsearch-dump

1、簡介:Elasticsearch導入導出工具。

支援操作包含但不限于:

1)、資料導出

  • 導出索引、檢索結果、别名或模闆為Json
  • 導出索引為gzip
  • 支援導出大檔案切割為小檔案
  • 支援統一叢集不同索引間或者跨索引資料拷貝

2)、資料導入

  • 支援Json資料、S3資料導入Elasticsearch。

2、位址:

https://github.com/taskrabbit/elasticsearch-dump

3、使用方法:

1elasticdump 
2  --input=http://production.es.com:9200/my_index 
3  --output=query.json 
4  --searchBody='{"query":{"term":{"username": "admin"}}}'           

如上,将檢索結果導出為json檔案。

更多導入、導出詳見github介紹。

4、使用效果:早期1.X版本沒有reindex操作,使用elasticdump解決跨叢集資料備份功能。效果可以。

5、推薦指數:五星。

Elasticsearch導出json首選方案。

4.3 logstashoutputcsv

步驟1:安裝logstashoutputcsv工具:

1D:logstash-6.5.4bin>logstash-plugin.bat  install  logstash-output-csv
2Validating logstash-output-csv
3Installing logstash-output-csv
4Installation successful           

步驟2:配置conf檔案核心的:輸入input,輸出ouput,中間處理filter都在如下的配置檔案中。

  1. 輸入:指定ES位址,索引,請求query語句;
  2. 輸出:csv輸出位址,輸出字段清單。
1input {
 2 elasticsearch {
 3    hosts => "127.0.0.1:9200"
 4    index => "company_infos"
 5    query => '
 6    {
 7        "query": {
 8            "match_all": {}
 9        }   
10    } 
11  '
12  }
13}
14
15output {
16  csv {
17    # elastic field name
18    fields => ["no", "name", "age", "company_name", "department", "sex"]
19    # This is path where we store output.   
20    path => "D:logstash-6.5.4exportcsv-export.csv"
21  }
22}           

步驟3:執行導出

1D:logstash-6.5.4bin>logstash -f ../config/logstash_ouput_csv.conf
 2Sending Logstash logs to D:/2.es_install/logstash-6.5.4/logs which is now configured via log4j2.properties
 3[2019-08-03T23:45:00,914][WARN ][logstash.config.source.multilocal] Ignoring the 'pipelines.yml' file because modules or command line options are specified
 4[2019-08-03T23:45:00,934][INFO ][logstash.runner          ] Starting Logstash {"logstash.version"=>"6.5.4"}
 5[2019-08-03T23:45:03,473][INFO ][logstash.pipeline        ] Starting pipeline {:pipeline_id=>"main", "pipeline.workers"=>8, "pipeline.batch.size"=>125, "pipeline.batch.delay"=>50}
 6[2019-08-03T23:45:04,241][INFO ][logstash.pipeline        ] Pipeline started successfully {:pipeline_id=>"main", :thread=>"#<Thread:0x34b305d3 sleep>"}
 7[2019-08-03T23:45:04,307][INFO ][logstash.agent           ] Pipelines running {:count=>1, :running_pipelines=>[:main], :non_running_pipelines=>[]}
 8[2019-08-03T23:45:04,740][INFO ][logstash.agent           ] Successfully started Logstash API endpoint {:port=>9600}
 9[2019-08-03T23:45:05,610][INFO ][logstash.outputs.csv     ] Opening file {:path=>"D:/logstash-6.5.4/export/csv-export.csv"}
10[2019-08-03T23:45:07,558][INFO ][logstash.pipeline        ] Pipeline has terminated {:pipeline_id=>"main", :thread=>"#<Thread:0x34b305d3 run>"}           
kibana 檢視有多少索引庫_幹貨 | Elasticsearch、Kibana資料導出實戰

位址:

https://medium.com/@shaonshaonty/export-data-from-elasticsearch-to-csv-caaef3a19b69

5、小結

根據業務場景選擇導出資料的方式。

kibana 檢視有多少索引庫_幹貨 | Elasticsearch、Kibana資料導出實戰

您的業務場景有導出資料需求嗎?如何導出的?歡迎留言讨論。

推薦閱讀:

《深入了解 Java 記憶體模型》讀書筆記

面試-基礎篇

Spring Boot 2.0 遷移指南

SpringBoot使用Docker快速部署項目

為什麼選擇 Spring 作為 Java 架構?

SpringBoot RocketMQ 整合使用和監控

Spring Boot 面試的十個問題

使用 Spring Framework 時常犯的十大錯誤

SpringBoot Admin 使用指南

SpringBoot Kafka 整合使用

SpringBoot RabbitMQ 整合使用

Elasticsearch索引增量統計及定時郵件實作

Elasticsearch實戰 | 必要的時候,還得空間換時間!幹貨 |《從Lucene到Elasticsearch全文檢索實戰》拆解實踐

JVM面試問題系列:JVM 配置常用參數和常用 GC 調優政策

Apache Flink 是如何管理好記憶體的?

上篇好文:

ELK 實時日志分析平台環境搭建

kibana 檢視有多少索引庫_幹貨 | Elasticsearch、Kibana資料導出實戰

繼續閱讀