Dec 11th, 2019 [EN][Kibana] Maps getting even better with 7.5: A practical example

Maps getting even better with 7.5: A practical example

Kibana Maps were already introduced in version 6.7. Since then each release brought fixes and also many new features and improvements to existing ones.

It was already possible to add color to a location and also custom color map based on chosen document value. This approach is simple and effective for many use cases. Later on we added possibility to use Icons instead of a circle and also coloring based on their value.

With the release of version 7.5 there is a new possibility for how to style your location points you are placing on the layer. As we add many new features to every Kibana release, this little improvement was not even mentioned in the blog post.

So what does that mean?

A simple but very practical example is public transportation location. With this dataset, you can plot position of public transportation vehicles on the map in real time (or every X seconds/minutes) using Kibana Maps. But not only showing their position, but also style them based on timestamp or 'how old' the location is.

Following image represents how such map can look like. Number of locations are filtered out for simplicity. Dark points are latest and fading over time.

Before version 7.5

Styling based on Date datatype was not possible.

The only option was to use numerical value instead. Even Date datatype is stored in Elasticsearch as date converted to UTC (if the time-zone is specified) and stored as a long number representing milliseconds-since-the-epoch. Kibana Maps was not able to work with the information.

There is a simple workaround which can be used. What if you subtract location’s Timestamp from now and store the value in separate field?

That is possible with Kibana scripted fields.

  • In Kibana navigate to Management -> Index Patterns
  • Choose your Index pattern where your documents are stored
  • Switch to Scripted fields panel
  • Click on Add scripted field
  • Add name, choose Number type and enter script you want:
    ZonedDateTime zdt = doc['date_time2'].value;
    double now = Math.abs(System.currentTimeMillis());
    return (now - zdt.toInstant().toEpochMillis());
  • Hit Save field to add new numerical field calculated on the fly

Please make sure that your timestamp is always available or do check if the value exists in your document.

You can now go to your Kibana Maps layer details where you add locations on the map and change your styling based on new scripted field age_of_position as in the following example.

Do not forget to Save your changes and check how style of your locations changes over time.

After version 7.5

With latest release there is nothing easier to do. Instead of creating a new Scripted field, you need to go straight to your layer Styling options and choose Date datatype as it will show up in the list of fields.
Note that Date fields were not listed in previous versions for styling when you accessed the list of fields.

Using Date datatype will now do exactly the same job as if using numerical difference between 2 timestamps.

We always try to improve and add new features and if you have new ideas what we should implement, let us know in Kibana GitHub repository.

2 Likes