# Help on pipeline aggregation

**URL:** <https://discuss.elastic.co/t/help-on-pipeline-aggregation/38160>\
**Category:** Elasticsearch\
**Created:** [December 30, 2015, 8:47am UTC](https://discuss.elastic.co/t/help-on-pipeline-aggregation/38160 "2015-12-30T08:47:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ebuildy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ebuildy/32/6070_2.png) [@ebuildy](https://discuss.elastic.co/u/ebuildy)\
**Post date:** [December 30, 2015, 8:47am UTC](https://discuss.elastic.co/t/help-on-pipeline-aggregation/38160/1 "2015-12-30T08:47:42Z")

</div>

Here documents:

`{"ip" : "1.1.1.1", "event" : "click"}`

Where IP is the user IP, EVENT the event (click | buy | home | basket ...).

I want to know the average count of each event, distinct by IP. Using SparkSQL with ES, this is done by this query:

```
SELECT AVG(total), event 
FROM (SELECT COUNT(*) AS total, client.ip, event.name AS event 
    FROM my
    GROUP BY event.name, client.ip HAVING total < 100) my2
GROUP BY event

```

That gives:

```
[1.5374449339207048,click]
[6.683713173985548,error]
[1.0,account.login.check]
[1.1481481481481481,account.login]
[1.2649006622516556,buy]
[1.25,settings.update]

```

In ES, I try to use the new pipeline aggregation but I didn't manage to find the right aggs imbrication to make it working ;-(

---

<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:** [July 5, 2017, 11:27pm UTC](https://discuss.elastic.co/t/help-on-pipeline-aggregation/38160/2 "2017-07-05T23:27:52Z")

</div>


