Group by on the sum of aggregation


I would like to know if there's a way to do an aggregation on the result of the sum.

Let's say I have 8 documents.

6 of them have 1 revision
2 of them have 2 revisions

I want to get :

1 : 6 hits
2 : 2 hits

This is what I managed to get for the moment :
We can see the number of revision for EACH document, that's already cool but not enough.

And this is what I would like (the black numbers indicating the number of "hits", remplace 8 by 6)


how is revision indicated in your documents ? i am assuming something like this:

{ id: 'doc1', rev: 1 }
{ id: 'doc2', rev: 1 }
{ id: 'doc3', rev: 1 }
{ id: 'doc1', rev: 2 }

you could try something like:

  • pie chart
  • split slices, term agg, rev field
  • leave count as a metric agg

Hi, Thank for the answer.

Actually the revision field is a personal scripted field by doing the sum of a field :
if(doc['operation'].value == "Revisionchange") { return 1; } return 0;

So if I'm doing the sum by splicing with docID it will give me the right number right ?

When I do the pie chart, splice by this scripted field and leave count as a metric I only have this pie :

Must I change the scripted field or do another operation ?

it doesn't seem you sum the revisions here ?
anyway, something like this won't be possible with pie chart at the moment ...

you would need to reindex your data so it contains the number of revisions as a field in your documents.

you could reindex your data in a new index by:

  • spliting on document id in the first index
  • getting the revision number by summing the revision field
  • index this in a new index

Okay so I have to reindex all the data and add the field documentVersion after all ^^'
Thank you for your help !

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