I have a use case, which I need some help with, please.
I'd like to create a metric in TSVB Table, where I can report the sum of a field, across a variable number (not fixed number) of documents.
i.e. if I have docs with 4 fields:
timestamp, qty, price, total spend
(where total spend = qty * price)
I'd like to be able to specify N qty, and get returned total spend values (which I can sum up) from the respective last Y documents (from latest to earliest in order), where their qty's sum up to N.
Where Y could be 1 if N is satisfied by the last/final document, or there could be >1 document returned whose qtys sum up to N.
I hope that is clear enough; I've not had any luck producing in Kibana, yet.
This type of request is deceptively complicated. Elasticsearch is not meant for this kind of problem in general, except for fetching documents in sorted time order. TSVB is definitely not capable of this, and will never be. Your best and probably only option is to write a Vega visualization. You would need to break this up into stages like this:
Collect the most recent 1000 documents (or some other high number) sorted by timestamp
Calculate a cumulative sum of the quantity and total spend in sorted order
Filter out any documents that have a cumulative sum of quantity > N
If N is intended to be dynamic, and not written into the script, then you also need a special user input section for this. There is only one visualization in Kibana which is capable of doing this, which is Vega.
I put together a sample Vega-Lite visualization which uses kibana sample data to calculate the total price of the first 100ish items sold in the timeframe:
I've not used the Vega vizs before, and it looks a bit more complex than other Kibana bits.
I'll take a look and see how I get on... Ah, I'm getting this error right now, so need to get Kibana updated: * The input spec uses vega-lite v4, but current version of vega-lite is 2.6.0.
However, am I right in thinking that Vega produces visualisations and not tables? I'm really looking to do this calculation as one of many metrics in a table. Is there anyway I could produce the metric with Vega and then pull into a table, perhaps?
Out of interest, aside from the Elastic/Kibana docs, are there any other third party Vega resources that will be helpful to look at, too?
You're right that it's a lot more complicated than our other visualizations, and that it doesn't produce tables. You could simulate a table layout using Vega.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.