I am trying to create a bar chart using the visualize section. Below is the example of the data in tabular format:
| timestamp | Id | category |
---------------------------------
| 08:49:10 | 1 | A |
| 08:50:20 | 1 | B |
| 09:00:10 | 1 | C |
| 09:00:50 | 2 | A |
| 09:01:20 | 2 | C |
| 09:20:00 | 3 | A |
| 09:20:10 | 3 | C |
| 09:20:30 | 3 | B |
What I want to achieve is a bar chart where the y-axis is the delta/difference in timestamp (in seconds) between category 'A' and 'C' with the same Id. Below is an example of the bar chart that I want to achieve using Kibana:
I have successfully made the visualization in Vega.
However, I have another use case which I have to use Canvas for the same specification.
Is this at all achievable with Canvas? Again, I have tried it but still unable to do so because it seems that Canvas does not support complex calculations for my use case.
Below is the expression that I used:
filters
| essql
query="SELECT DATE_DIFF('seconds', \"@timestamp\", NOW()) AS old, Id FROM \"" {var "IndexName"} "\" where category = 'C'"
| staticColumn name="new"
value={filters | essql query={string "SELECT DATE_DIFF('seconds', \"@timestamp\", NOW()) AS new FROM \"" {var "IndexName"} "\" where category = 'A'"}}
| pointseries x="Id" y="old-new"
| plot defaultStyle={seriesStyle bars=3}
| render
I am aware that this is not how to use static column. However, is there any function that allows us to store a table of value that can later be used for calculation purposes?
You can use var_set to create a variable, which could be set based on the result of a query. You can use the string function to construct strings from parts, which can be used to generate SQL queries. Also, you can use the ply function to perform math similar to what you'd do in a pivot table.
Just a quick question on that, can we store the result of a query that produces multiple rows of values (time difference for each Id) in a variable or anything?
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.