Customize Kibana Region Maps
With GeoJSON Boundaries
Background
On my previous post I have discussed about using different visualizations(graphs, charts, matrixes, tables etc) with Kibana. In this post I’m gonna discuss about visualizing the data with Kibana Region Maps. Region Maps in Kibana are a better solution to represent a whole area or region. All the source codes which related to this post available in gitlab. Please clone the repo and continue the post.
Run Elasticsearch
To run Elasticsearch
I have used Elassandra
docker image. Elassandra built by combining Elasticseach with Cassandra
. It comes Elasticsearch as a Cassandra plugin. Basically it has Cassandra API as well as Elasticsearch API. When data save on Cassandra it will automatically index on Elasticsearch. Read more about elassandra from here. Following is the docker-compose.yml
to run the Elassandra.
Elasticsearch Index
I have a Elasticsearch index vote
. It contains mock election result data of Sri Lankan elections in past few years. To create the index and migrate sample data into the index, I have used a separate service Aplos
. When running Aplos
service, it creates Elasticsearch index and populate data on to it. Following is the docker-compose.yml
to run the Aplos
service.
Following is the structure of the vote
Elasticsearch index. This index can be configured in Kibana. There is a field district
in the vote
index which I have used to build region maps.
GeoJSON Geo-Boundaries
Kibana provides region maps of several default regions(e.g World Countries
, US States
, Australia States
etc). To have maps with custom regions(regions which does not provide in default Kibana) we need to get the geo-boundaries of the regions as GeoJSON format
. GeoJSON is an open standard format designed for representing simple geographical features, along with their non-spatial attributes, based on the JSON format. Once get the GeoJSON boundaries of the regions, we can overlay them on the Elastic Map Service to display aggregations for custom geographical areas natively in Kibana. In this example I’m using Kibana Maps to visualize election results of different districts in Sri Lanka. For that, first I have obtained the geo-boundaries of Sri Lankan districts into GeoJSON file named electorate.json
.
GeoJSON Http Server
To build custom maps in Kibana, we need to host our GeoJSON files in CORS
enabled HTTP/HTTPS
web server. So in here I have built simple CORS enabled web server with nodejs http-server
package to serves the electorate.json
file. Following is the Dockerfile
and docker-entry.sh
I have used dockerize http-server.
Following is the docker-compose.yml
entry to run the dockerized nodejs http-server
instance.
Kibana Config File
Next I have defined the information in the electorate.json
GeoJSON file(url
, fields
etc) in the Kibana config. Following is the kibana.yml
config file which defined the electorate.json
GeoJSON file information.
The URL of the hosted GeoJSON file is http://geo:800/electorate.json
. In here the geo
is the host name of the http-server service I have built to host the GeoJSON file. The GeoJSON file contains a filed called electoralDistrict
which defines the district name. In the Kibana config file I have defined that field information as well. Following is the docker-compose.yml
entry to run the Kibana with given config file. In here I have defined a link to http-server(geo
). It will add geo
host name entry into the /etc/hosts
file of the Kibana docker container. Then Kibana service can serve the http-server via the geo
host name.
Run services
Now I can start the services in the following order. The Aplos
service will create Elasticsearch index and bootstrap data into it.
Configure Kibana Index
To create the map, first I need to define the Elastisearch index in the Kibana, it can be done in following way.
Create Map
Then I can create a region map with vote
index by joining the data on the electorate.json
GeoJSON file. When creating the region map, I need to specify the field(identified as Join field
) in the Elasticsearch index(district
) which matches to the field in the GeoJSON file(electorateDistrict
). This field matching can be define from the Buckets shape field
aggregation in the region map configuration. Following are the main configuration I have done in the map.
- Aggregation Matrix
Sum of party_votes
- Bucket Shape field
Terms district
- Layer settings
Vectors map Sri Lanka Districts
- Join field
district
Once created the map with these configurations, Kibana will visualize the sum of party_votes in different districts in Sri Lanka with different colors. Kibana provides different color themes(e.g greens
, reds
, yellow to read
, green to red
etc) to visualize the data.
Reference
- https://www.programmersought.com/article/16914636804/
- https://blog.mimacom.com/custom-region-map/
- https://www.tutorialspoint.com/kibana/kibana_working_with_region_map.htm
- https://towardsdatascience.com/covid-19-map-using-elk-7b8611e9f2f4
- https://spoon-elastic.com/all-elastic-search-post/kibana-map-on-the-elastic-stack-7-6/