How to use Bucket Script


I’m just trying to figure out how to use the Metric Bucket script for Elasticsearch (Grafana 6.0.2, Elasticsearch 5.2.2).
I followed the link of the “Whats new” documentation and read the Elasticsearch documentation.

Special I can’t get any further with the field ‘select metric’.
Everything I enter is discarded immediately and does not end up in the query “buckets_path”.

I have tried the following input:
“sum”:{“field”: “”}

Can someone give me a simple input to get the stone to roll?

Thank you very much.
Jan L.

Ok, I got it now.
‘select metric’ field will get some drop-down values, after adding additional Metric fields to the query.

Could you please show how the problem is solved?(maybe in the same form as the first picture you posted)

I put a picture from Grafana version 8.1, put it is the same as for older versions.

  1. You have to put at least one Metric to your query (here 2 times sum, but you can use any metric, as I understand).
  2. You can select the Metric in the Bucket Script Variables and give it a name
  3. You can call the variable in Script part by adding params. before the name

1 Like

thank you, this is a good answer

1 Like

Can you please help me how can i achieve this

There are many entries per gene. That is, I have:

Gene  Tag   Annotation
----- ----- ---------------
A1BG  tag1  first gene
A2M   tag1  a-macroglobulin
A2M   tag2  second gene
BRCA1 tag1  breast cancer 1
BRCA1 tag3  important gene

I want to query these data, aggregate and sort by gene, and get something like this:

Gene   Tags        Annotations
------ ----------- -------------------------------
A1BG   tag1        first gene
A2M    tag1; tag2  a-macroglobulin; second gene
BRCA1  tag1; tag3  breast cancer 1; important gene

in Elastic search and show it in grafana.?

Hi subodh2711,

I do not know is this is possible. If it is, I do not know how.
I such a case I always fill the data already comma separated into the Elasticsearch Index.

+1 waiting for this feature in grafana