Kibana6|Kibana6 入门1 - 加载样例数据

官方文档开始部分的说明,介绍,安装都很简单,就不翻译了。跟以前的版本也没啥太大的区别。
从 Tutorial 的 Getting Started 章节开始。
加载样例数据 本章节要加载的样例数据集如下:

  • 莎士比亚全集,并且已经进行了属性的切分,下载地址 shakespeare.json。
  • 随机数据组成的虚拟账户集合,下载地址 accounts。
  • 随机生成的日志文件集合,下载地址 logs.jsonl.gz。
对于压缩文件需要解压
unzip accounts.zip gunzip logs.jsonl.gz

莎士比亚全集的数据结构:
{ "line_id": INT, "play_name": "String", "speech_number": INT, "line_number": "String", "speaker": "String", "text_entry": "String", }

账户数据结构:
{ "account_number": INT, "balance": INT, "firstname": "String", "lastname": "String", "age": INT, "gender": "M or F", "address": "String", "employer": "String", "email": "String", "city": "String", "state": "String" }

日志的数据结构有很多不同属性,但本教程使用的属性如下:
{ "memory": INT, "geo.coordinates": "geo_point" "@timestamp": "date" }

加载莎士比亚全集和日志文件集合之前,需要建立属性映射。映射会将索引中的文档进行逻辑分组,并确定属性的特性。比如属性是否支持搜索,是否可以被分词,是否可以被切分为单独的词。
使用如下命令在Elasticsearch上为莎士比亚全集建立映射:
curl -XPUT 'localhost:9200/shakespeare?pretty' -H 'Content-Type: application/json' -d' { "mappings": { "doc": { "properties": { "speaker": {"type": "keyword"}, "play_name": {"type": "keyword"}, "line_id": {"type": "integer"}, "speech_number": {"type": "integer"} } } } }'

根据映射的定义, 莎士比亚全集的数据具有如下特性:
  • speakerplay_name 属性是关键字,所以它们不会被分词。这些字符串即使由多个单词组成,也会被当作一个完整独立的个体。
  • line_idspeech_number 是整形的。
    可以通过在这些属性上使用 type geo_point,将日志文件中的纬度/经度进行标记,映射为地理信息。
    使用如下命令在日志中建立geo_point映射:
curl -XPUT 'localhost:9200/logstash-2015.05.18?pretty' -H 'Content-Type: application/json' -d' { "mappings": { "log": { "properties": { "geo": { "properties": { "coordinates": { "type": "geo_point" } } } } } } }'

curl -XPUT 'localhost:9200/logstash-2015.05.19?pretty' -H 'Content-Type: application/json' -d' { "mappings": { "log": { "properties": { "geo": { "properties": { "coordinates": { "type": "geo_point" } } } } } } }'

curl -XPUT 'localhost:9200/logstash-2015.05.20?pretty' -H 'Content-Type: application/json' -d' { "mappings": { "log": { "properties": { "geo": { "properties": { "coordinates": { "type": "geo_point" } } } } } } }'

【Kibana6|Kibana6 入门1 - 加载样例数据】账户数据集不需要映射。
使用 Elasticsearch [bulk] API 来加载数据集合:
curl -H 'Content-Type: application/x-ndjson' -XPOST 'localhost:9200/bank/account/_bulk?pretty' --data-binary @accounts.json curl -H 'Content-Type: application/x-ndjson' -XPOST 'localhost:9200/shakespeare/doc/_bulk?pretty' --data-binary @shakespeare_6.0.json curl -H 'Content-Type: application/x-ndjson' -XPOST 'localhost:9200/_bulk?pretty' --data-binary @logs.jsonl

执行下面的命令来验证是否成功:
curl -XGET 'localhost:9200/_cat/indices?v&pretty'

结果应该如下:
health status indexpri rep docs.count docs.deleted store.size pri.store.size yellow openbank5110000418.2kb418.2kb yellow openshakespeare51111396017.6mb17.6mb yellow openlogstash-2015.05.18514631015.6mb15.6mb yellow openlogstash-2015.05.19514624015.7mb15.7mb yellow openlogstash-2015.05.20514750016.4mb16.4mb

    推荐阅读