Json input - calculated with derived values like unique-count

Hi, I know how to use json input to display a simple calculation on 2 fields.
For example

{ "script": 
"_value / doc['number_field1'] .value "
}

What I don't know is how to do a calculation on an aggregated field. For example unique count.
For example

{ "script": 
"_value / unique_count(doc['number_field1'] .value) "
}

In my visialization I created a line graph showing the unique count over time.
So is there a way to access that field in the visualization?

Thank you!

You can just create a Metric visualization if you just want to display that unique count;

I wish, it's a line graph showing unique_count(field A) and unique_count(field B) over time.
I just need to show a calculation of those 2
unique_count(field A) / unique_count(field B) over time

I'm 100% sure there is a way, because it's fields in the JSON that creates the graph elements.
Not familiar enough with Kibana to find out how.

OK, for the simple case, you can just use the unique count metric like this;

If you need to divide 2 unique counts over time, I think the Visual Builder could do that.

In the Visual Builder unique count is Cardinality.

It starts looking very similar like this;

I can add a second metric, and then a third that I switch to a Calculation. Then create a variable for each of the 2 metrics. Then use them in a simple division.

Does this get you what you're looking for?

2 cardinality fields created, and then the "calculation" option is grayed out.
Maybe because I am using cardinality with string/keyword fields?

There was an issue about that. What version are you on?

6.2.1

I tried one more thing - took 2 metrics who's average is known to me and calculation was allowed this time (great!) but the result just gave me nothing. See screenshot
In the data - the first average is 21 and the second is 15, so I was hoping to see 1.4

Can you show a screenshot of the "Time Series" tab? By default, the Metric tab you're on will show the last value in your Time Series. So if that Time Series drops off to 0 at the end, that's what you would see in the Metric tab. But there is a way to get the overall average as well.

Screenshot attached - when putting either field on top there is no zero value.
Interesting. How do I get the overall average?

This is kind of a long discuss thread but there are some notes about using Overall Average in it;

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.