# Aggregation post processing

**URL:** <https://discuss.elastic.co/t/aggregation-post-processing/22748>\
**Category:** Elasticsearch\
**Created:** [March 18, 2015, 9:55pm UTC](https://discuss.elastic.co/t/aggregation-post-processing/22748 "2015-03-18T21:55:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Chang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daniel_chang/32/820_2.png) [@Daniel\_Chang](https://discuss.elastic.co/u/Daniel_Chang)\
**Post date:** [March 18, 2015, 9:55pm UTC](https://discuss.elastic.co/t/aggregation-post-processing/22748/1 "2015-03-18T21:55:27Z")

</div>

Hi all,

Are there any ways to perform post-processing on aggregation results with  
elasticsearch version 1.4.4?

My scenario is as follows: for every document of type X, we want to find  
out how many of its nested documents matches specific criteria, which are  
divided into buckets with the filters aggregation.  
For example: see [https://gist.github.com/mwdchang/067c64097589d6983ed3](https://gist.github.com/mwdchang/067c64097589d6983ed3)

However we want to score/sort the documents based on how many nested  
documents are matched in each bucket, with different weightings.

For example: score = buckets[0].doc\_count \* 0.2 + buckets[1].doc\_count \*  
0.7 + buckets[2].doc\_count \* 0.1

I don't think this can be done inside a scripted field, as our filters  
criteria may reference other documents per  
([http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-filter.html#\_terms\_lookup\_mechanism](http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-filter.html#_terms_lookup_mechanism))  
We also have close to 13 million documents so we would like to avoid  
bringing the post processing to client side.

Any help or advice would be appreciated.

Thanks,  
~Daniel

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/68d23f54-9f72-4337-bbaa-589f2c07f316%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/68d23f54-9f72-4337-bbaa-589f2c07f316%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 12:25am UTC](https://discuss.elastic.co/t/aggregation-post-processing/22748/2 "2017-07-06T00:25:42Z")

</div>

Closed on July 6, 2017, 12:25am UTC


