How to do the sum aggregation based on unique id


(NETHAJI) #1

Hi ELK Folks,

I have a doubt on sum aggregation,

My sample data contains three columns

id status_id cost
1 1 1000
1 5 1000
1 6 1000
2 1 2000
3 1 3000
3 5 3000
4 6 1000

I'm having data like this , if i do the sum aggregation for cost means it shows 12000 i.e., it calculate the total value.

I don't want like this, i need the sum aggregation based on unique id, i.e., my expected result is 7000

here I couldn't able to get the correct output

please provide some solution to achieve the correct output.


(Nick Peihl) #2

Hi Nethanji,

You are looking for a terms aggregation. In your case it might look like this.

GET _search/
{
  "aggs": {
    "total_cost": {
      "terms": {
        "field": "id",
        "size": 4
      },
      "aggs": {
        "cost": {
          "sum": {
            "field": "cost"
          }
        }
      }
    }
  }
}

(NETHAJI) #3

Hi,
Thank you for your reply

I need to show this in gauge report.


(system) #4

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