Kibana Lens Formulas
tl;dr
- With version 7.14.0 Kibana Lens has extended with the feature “Formula”
- Lens can combine now aggregations and mathematical functions and unites its simplicity and user-friendliness with a powerful tool
- Aggregation is not anymore based on a field like in previous Lens versions, the aggregation can now be a product of multiple fields
The goal
Per trade, a JSON document is generated with a field for the number of bought shares (quantity) and another field for the actual price per share (spot_price)
The weight inside the whole portfolio of the value of the asset classes and the value of the symbols inside their respective asset-class should be calculated and presented in a donut diagram.
this is done by two aggregations:
- one with the buckets for the asset-classes
- the other one as a sub-aggregation of asset classes holds the buckets for the specific symbols. To get the value per symbol, in each document the spot_price must be multiplied by the quantity.
HowTo
For the donut visualization, the fields “asset_class” and “symbol” need to be dragged to the workspace. Once done, click on “Size by” in the Donut menu:
To calculate the value of the transaction, you need a formula, because the basic functions can only be applied to an existing metric field. What you need is a product of two fields, which the new Formula editor will provide you:
You can see now correct calculated buckets with the value of the asset classes and their symbols, in relation to the value of the portfolio:
Kibana has a lot more predefined mathematical functions. Here you can see a few of them:
Resources
For more information about Lens and Formulas, I recommend visiting elastic.co