# Aggregation operation on Elastic search data

**URL:** <https://discuss.elastic.co/t/aggregation-operation-on-elastic-search-data/123695>\
**Category:** Elasticsearch\
**Created:** [March 13, 2018, 8:48am UTC](https://discuss.elastic.co/t/aggregation-operation-on-elastic-search-data/123695 "2018-03-13T08:48:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kish](https://avatars.discourse-cdn.com/v4/letter/k/71e660/32.png) [@kish](https://discuss.elastic.co/u/kish)\
**Post date:** [March 13, 2018, 8:48am UTC](https://discuss.elastic.co/t/aggregation-operation-on-elastic-search-data/123695/1 "2018-03-13T08:48:28Z")

</div>

I have below data but i need to build a query which will give the average of CpuAverageLoad of specific Nodetype. Kibana cannot used because of some license issue.

```
> { "took" : 6, "timed_out" : false, "_shards" : {
> "total" : 5,
> "successful" : 5,
> "failed" : 0 }, "hits" : {
> "total" : 11,
> "max_score" : 1.0,
> "hits" : [
> {
> "_index" : "kpi",
> "_type" : "kpi",
> "_id" : "AWIZB9Ds_xnN0Y7Qo1A7",
> "_score" : 1.0,
> "_source" : {
> "date" : "2018-03-12 12:36:05",
> "kpi" : [
> {
> "CpuAverageLoad" : 3,
> "HaGroupId" : "1001",
> "LbGroupId" : "",
> "MemFree" : 100,
> "MemUsed" : 0,
> "NodeId" : "kishan",
> "NodeType" : "tpt",
> "State" : "online",
> "Static_limit" : 0
> },
> {
> "CpuAverageLoad" : 0,
> "HaGroupId" : "102",
> "LbGroupId" : "",
> "MemFree" : 0,
> "MemUsed" : 0,
> "NodeId" : "kalyan",
> "NodeType" : "tpt1",
> "State" : "online"
> }
> ]
> }
> },
> ......

> {
> "_index" : "kpi",
> "_type" : "kpi",
> "_id" : "AWIZCLsE_xnN0Y7Qo1A8",
> "_score" : 1.0,
> "_source" : {
> "date" : "2018-03-12 12:37:05",
> "kpi" : [
> {
> "CpuAverageLoad" : 3,
> "HaGroupId" : "1001",
> "LbGroupId" : "",
> "MemFree" : 100,
> "MemUsed" : 0,
> "NodeId" : "kishan",
> "NodeType" : "tpt",
> "State" : "online",
> "Static_limit" : 0
> },
> {
> "CpuAverageLoad" : 0,
> "HaGroupId" : "102",
> "LbGroupId" : "",
> "MemFree" : 0,
> "MemUsed" : 0,
> "NodeId" : "kalyan",
> "NodeType" : "tpt1",
> "State" : "online"
> }
> ]
> }
> },
> {
> "_index" : "kpi",
> "_type" : "kpi",
> "_id" : "AWIZCVc9H8WRs8qwDKh5",
> "_score" : 1.0,
> "_source" : {
> "date" : "2018-03-12 12:37:45",
> "kpi" : [
> {
> "CpuAverageLoad" : 0,
> "HaGroupId" : "1001",
> "LbGroupId" : "",
> "MemFree" : 100,
> "MemUsed" : 0,
> "NodeId" : "kishan",
> "NodeType" : "tpt",
> "State" : "online",
> "Static_limit" : 0
> },
> {
> "CpuAverageLoad" : 0,
> "HaGroupId" : "102",
> "LbGroupId" : "",
> "MemFree" : 0,
> "MemUsed" : 0,
> "NodeId" : "kalyan",
> "NodeType" : "tpt1",
> "State" : "online"
> }
> ]
> }
> },
> {
> "_index" : "kpi",
> "_type" : "kpi",
> "_id" : "AWIZCkGnH8WRs8qwDKh6",
> "_score" : 1.0,
> "_source" : {
> "date" : "2018-03-12 12:38:45",
> "kpi" : [
> {
> "CpuAverageLoad" : 1,
> "HaGroupId" : "1001",
> "LbGroupId" : "",
> "MemFree" : 100,
> "MemUsed" : 0,
> "NodeId" : "kishan",
> "NodeType" : "tpt",
> "State" : "online",
> "Static_limit" : 0
> },
> {
> "CpuAverageLoad" : 0,
> "HaGroupId" : "102",
> "LbGroupId" : "",
> "MemFree" : 0,
> "MemUsed" : 0,
> "NodeId" : "kalyan",
> "NodeType" : "tpt1",
> "State" : "online"
> }
> ]
> }
> }
> ] } }

```

I have tried with below query

curl -XGET 'localhost:9200/\_search?pretty' -H 'Content-Type: application/json' -d'  
{  
"query": {  
"bool" : {  
"must" : {  
"script" : {  
"script" : {  
"inline" : "doc['kpi.CpuAverageLoad'].value \> params.param1",  
"lang" : "painless",  
"params" : {  
"param1" : 5  
}  
}  
}  
}  
}  
}  
}

I am unable to build a porper query which we give me the average of CpuAverageLoad for specific nodetype i mention

---

<div class="post-metadata">

**Author:** ![kish](https://avatars.discourse-cdn.com/v4/letter/k/71e660/32.png) [@kish](https://discuss.elastic.co/u/kish)\
**Post date:** [March 13, 2018, 8:52am UTC](https://discuss.elastic.co/t/aggregation-operation-on-elastic-search-data/123695/2 "2018-03-13T08:52:47Z")

</div>

i tried below query

> curl -XPOST 'localhost:9200/kpi/\_search?size=0&pretty' -H 'Content-Type: application/json' -d'  
> {  
> "aggs" : {  
> "avg\_grade" : {  
> "avg" : {  
> "script" : {  
> "source" : "doc.['kpi.CpuAverageLoad']value"  
> }  
> }  
> }  
> }  
> }'

But i getting below error

> {  
> "error" : {  
> "root\_cause" : [  
> {  
> "type" : "illegal\_argument\_exception",  
> "reason" : "[script] unknown field [source], parser not found"  
> }  
> ],  
> "type" : "illegal\_argument\_exception",  
> "reason" : "[script] unknown field [source], parser not found"  
> },  
> "status" : 400  
> }

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 10, 2018, 8:53am UTC](https://discuss.elastic.co/t/aggregation-operation-on-elastic-search-data/123695/3 "2018-04-10T08:53:08Z")

</div>

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