"Group by" not working on data

I’m trying to graph a number from one field and aggregate it based on the text element in another field.

My data is sourced from Elasticsearch and it’s a collection of results from elemental analysis, i.e. name of the element and its quantity from each measurement.

So f.x. for one measurement, where I measurement two elements, say Al (Aluminium) and Fe (Iron), I would get these two documents:

   { 
      "data.Quantifications.Element" : "Al",
      "data.Quantifications.Quantity" : 0.012,
      "timestamp" : "2020-02-15@15:25:37:321"
   }

   { 
      "data.Quantifications.Element" : "Fe",
      "data.Quantifications.Quantity" : 0.032,
      "timestamp" : "2020-02-15@15:25:37:321"
   }

Both these documents will have the same timestamp since they belong to the same measurement.

If I do another measurement I’ll get another set of documents, with different quantity and timestamp.

My goal is to graph the Quantity field but aggregate it (group by) the Element field. So it would look something like this:

Now I’we set up a dashboard that shows the Max of Quantity with this query:

And I able to get a graph based on all measurements, but not taking in the which-element information.

But then when I try to group it by Element it doesn’t work as I would expect it to:

However I’m able to get some aggregated results if I display it in table view:

So Grafana is aggregating it for sure, but seems to be aggregating over the whole period, and throwing away the timestamp information.

Anyone know how to solve this puzzle? :slight_smile:

(sorry for just posting links but not photos, the forum didn’t allow me to post more than 2 pictures inline)

Can you try it with 2 group-by’s?

Metric       Max              data.quantifications.quantity
Group By     Terms            data.Quantifications.Element.keyword
Group By     Date Histogram   Timestamp