尝试使用「Embulk + Elasticsearch + Kibana」将数据绘制到地图上(备忘录)
首先
- Embulk + Elasticsearch + kibana + OpenStreetMapでお手軽に地理情報を可視化
在上面的帖子中,以「Embulk + Elasticsearch + kibana」的组合将AED设施的位置简单地映射到地图上,内容非常有趣。
最终,我们在kibana的地图(OpenStreetMap)上将AED标记出来并显示。

因为对「Embulk + Elasticsearch + kibana」感兴趣,所以我在自己的环境中尝试了一下帖子的内容。尽管只是尝试了原文的内容,但由于操作系统(原文是MacOS)和Elasticsearch/kibana的版本不同,所以我将其作为备忘录留下来。
环境
我使用的环境如下所示。
-
- CentOS 7.5
-
- Elasticsearch 6.8.3
- kibana 6.8.3
CentOS已预先将firewalld设置为禁用状态。
同时,Elasticsearch和Kibana可以从以下位置下载。
https://www.elastic.co/jp/downloads/past-releases/elasticsearch-6-8-3
https://www.elastic.co/jp/downloads/past-releases/kibana-6-8-3
以下是两个链接,一个是Elasticsearch-6.8.3的下载页面链接,另一个是Kibana-6.8.3的下载页面链接。
最初使用的是7.4版本,但由于类型消失等重大更改以及信息不完整,因此决定使用6系列的最新版本6.8.3。
安装JDK8
在安装Elasticsearch/Kibana之前,请按照以下步骤安装OpenJDK8。
# yum install java-1.8.0-openjdk-devel
# java -version
openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-b10)
OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)
我正在设置 JAVA_HOME,并将 Java 路径添加到 PATH 中。
# echo "export JAVA_HOME=$(readlink -e $(which java)|sed 's:/bin/java::')" > /etc/profile.d/java.sh
# echo "PATH=\$PATH:\$JAVA_HOME/bin" >> /etc/profile.d/java.sh
# source /etc/profile
获取AED信息
使用AED信息在地图上进行标记。
我们将从AED开放数据平台下载东京都的AED信息。
$ curl https://aed.azure-mobile.net/api/aedinfo/%E6%9D%B1%E4%BA%AC%E9%83%BD/ -o aedinfo_tokyo.json
安装Elasticsearch
请按照以下步骤下载Elasticsearch,并进行安装和自动启动服务的设置。
# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.8.3.rpm
# rpm -ivh elasticsearch-6.8.3.rpm
# systemctl enable elasticsearch.service
# systemctl start elasticsearch.service
使用curl命令确认可以访问Elasticsearch。
# curl http://localhost:9200
{
"name" : "s0nDSnH",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "OFFAczRGRUKAqFcqyBnFsg",
"version" : {
"number" : "6.8.3",
"build_flavor" : "default",
"build_type" : "rpm",
"build_hash" : "0c48c0e",
"build_date" : "2019-08-29T19:05:24.312154Z",
"build_snapshot" : false,
"lucene_version" : "7.7.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
我們會修改設定檔以便於外部連接。
# vi /etc/elasticsearch/elasticsearch.yml
#network.host: 192.168.0.1
network.host: 0.0.0.0 # アクセスできるIPアドレスを指定する。0.0.0.0で全て許可。
transport.host: localhost # 追加
在更改设置后,重新启动Elasticsearch。
# systemctl restart elasticsearch
Kibana的安装
按照以下步骤下载Kibana,并设置自动安装和服务启动:
# wget https://artifacts.elastic.co/downloads/kibana/kibana-6.8.3-x86_64.rpm
# rpm -ivh kibana-6.8.3-x86_64.rpm
# systemctl enable kibana.service
# systemctl start kibana.service
我们要通过curl命令确认能够访问Kibana。
# curl http://localhost:5601
我会修改设置文件,以便外部可以连接。
# vi /etc/kibana/kibana.yml
#server.host: "localhost"
server.host: "0.0.0.0"
更改设置后,重新启动Kibana。
# systemctl restart kibana.service
当您在浏览器中访问以下地址时,Kibana的首页将会打开。
http://[IP地址]:5601

Embulk的安装
按照官方网站的“快速入门”指南来进行安装。
- Quick Start
# curl --create-dirs -o ~/.embulk/bin/embulk -L "https://dl.embulk.org/embulk-latest.jar"
# chmod +x ~/.embulk/bin/embulk
# echo 'export PATH="$HOME/.embulk/bin:$PATH"' >> ~/.bashrc
# source ~/.bashrc
我也会安装插件。
# embulk gem install embulk-parser-jsonpath embulk-output-elasticsearch
# embulk gem install embulk-filter-insert embulk-filter-ruby_proc embulk-filter-column
创建Elasticsearch模式。
将schema.json文件按照以下方式创建。
{
"index_patterns": ["aedmap*"],
"settings": {
"number_of_shards": 1
},
"mappings": {
"aed_schema": {
"properties": {
"LocationName": {
"type": "text"
},
"address": {
"type": "text"
},
"location": {
"type": "geo_point"
}
}
}
}
}
将之前创建的模式文件注册到Elasticsearch中。
# curl -H 'Content-Type:application/json' -XPUT localhost:9200/_template/aedmap -d @schema.json
{"acknowledged":true}
使用Embulk将AED文件加载到Elasticsearch中。
使用Embulk创建将AED文件加载到Elasticsearch的配置文件(config.yml)如下所示。
in:
type: file
path_prefix: ./aedinfo_tokyo.json
parser:
charset: UTF-8
newline: CR+LF
type: jsonpath
columns:
- {name: Id, type: long}
- {name: LocationName, type: string}
- {name: Perfecture, type: string}
- {name: City, type: string}
- {name: AddressArea, type: string}
- {name: Latitude, type: double}
- {name: Longitude, type: double}
filters:
- type: insert
columns:
- location: ''
- address: ''
- type: ruby_proc
columns:
- name: location
proc: |
->(_,record) do
return record['Latitude'].to_s + "," + record['Longitude'].to_s
end
skip_nil: false
type: string
- name: address
proc: |
->(_,record) do
return record['Perfecture'].to_s + record['City'].to_s + record['AddressArea'].to_s
end
skip_nil: false
type: string
- type: column
columns:
- {name: LocationName, type: string}
- {name: address, type: string}
- {name: location, type: string}
#out: {type: stdout}
out:
type: elasticsearch
index: aedmap-tokyo-index3
index_type: aed_schema
nodes:
- {host: 127.0.0.1}
当试图确认输出结果的预览时,出现了以下错误。
# embulk preview config.yml
~省略~
2019-10-04 07:15:40.495 +0200 [WARN] (0001:preview): Skipped invalid record (org.embulk.spi.DataException: com.jayway.jsonpath.InvalidJsonException: com.fasterxml.jackson.core.JsonParseException: Unexpected end-of-input: was expecting closing '"' for name
at [Source: java.io.InputStreamReader@55adcf9e; line: 1, column: 34689])
似乎是在说数据有问题,但实际上使用embulk run命令运行时没有问题,让人感到不舒服不知道原因,但还是会继续工作。
[2019/10/4附注]
上述错误的发生是因为文件大小超过了限制。预览命令默认设定为32KB,如果文件大小超过了限制,就需要通过选项进行调整。
通过在config.yml文件的开头添加以下两行,就能成功执行预览了。
(看来不能不认真地阅读手册呢)
- Configuration(Preview executor)
exec:
preview_sample_buffer_bytes: 4194304 # 512kb
执行结果如下所示。
~省略~
+---------------------------+------------------------------+-------------------------+
| LocationName:string | address:string | location:string |
+---------------------------+------------------------------+-------------------------+
| 三鷹市東部市政窓口 | 東京都三鷹市中原1-29-35 | 35.6671705,139.5759333 |
| 東台小学校 | 東京都三鷹市中原2-17-37 | 35.6673969,139.5720452 |
| 東部水再生センター | 東京都三鷹市新川1-1-1 | 35.6679287,139.5784636 |
~省略~
根据预览命令可以确认,我将进行Elasticsearch加载的执行。
# embulk run config.yml
执行后,从Kibana中选择”Management”-“Index Management”,可以看到索引已经被创建,并且可以通过”Docs count”了解到文档已经被注册。

当Health变为”yellow”时,执行以下命令将变为”green”。
# curl -H "Content-Type: application/json" -XPUT localhost:9200/*/_settings -d '{"number_of_replicas":0}'
{"acknowledged":true}

在Kibana中显示地图.
数据输入已经完成,现在我们将在Kibana上地图上显示AED的位置。
首先选择“Visualize” – “+”选项。

接下来,在“新的可视化”中选择“坐标地图”。

选择[Buckets]的聚合(“Aggregation”)为”GeoHash”,字段(“Field”)为”Location”。

3.Qui-提携 Sogou公司 利用 SoGou-为 出品 SoGou输入法.ai

由于说明已经被大大简化,请参考原文以获取更详细的信息(在原文中点赞原文的精彩内容吧!)
请提供更详细的上下文,这样我可以更准确地为您完成翻译。谢谢!
-
- Embulk + Elasticsearch + kibana + OpenStreetMapでお手軽に地理情報を可視化
-
- Install Kibana with RPM
-
- Elasticsearch+Kibanaを設定してみる(CentOS7.4編)
- Configuration(Preview executor)