# Query related to Scripts on Facets

**URL:** <https://discuss.elastic.co/t/query-related-to-scripts-on-facets/7551>\
**Category:** Elasticsearch\
**Created:** [May 3, 2012, 2:29pm UTC](https://discuss.elastic.co/t/query-related-to-scripts-on-facets/7551 "2012-05-03T14:29:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rahul\_Sharma](https://avatars.discourse-cdn.com/v4/letter/r/df705f/32.png) [@Rahul\_Sharma](https://discuss.elastic.co/u/Rahul_Sharma)\
**Post date:** [May 3, 2012, 2:29pm UTC](https://discuss.elastic.co/t/query-related-to-scripts-on-facets/7551/1 "2012-05-03T14:29:40Z")

</div>

Hi,

Currently if I am not wrong scripts are run on each document. Can it be  
done at Facet level. _For example_:

I have terms A and B which are part of an Index. Now I need an additional  
term C = A \* B and then I do aggregation on all 3 terms.  
For term C I use _statisticalScriptFacet_ and for rest I use \*  
statisticalFacet\*

But looks like the script executes at each document level so it becomes  
equivalent to Sum (A1 \* B1 + A2 \* B2 + A3 \* B3 + .........+ An \* Bn)

Whereas I need ---- Sum (A) \* Sum (B)

Is there any easy way of achieving it without handling at the client level?

Thanks  
Rahul

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [May 4, 2012, 1:23pm UTC](https://discuss.elastic.co/t/query-related-to-scripts-on-facets/7551/2 "2012-05-04T13:23:04Z")

</div>

Can'y you run one facet on A, one facet on B, and then multiple them on  
your end?

On Thu, May 3, 2012 at 5:29 PM, Rahul Sharma  
[rahul.sharma.coder@gmail.com](mailto:rahul.sharma.coder@gmail.com)wrote:

> Hi,
> 
> Currently if I am not wrong scripts are run on each document. Can it be  
> done at Facet level. _For example_:
> 
> I have terms A and B which are part of an Index. Now I need an additional  
> term C = A \* B and then I do aggregation on all 3 terms.  
> For term C I use _statisticalScriptFacet_ and for rest I use \*  
> statisticalFacet\*
> 
> But looks like the script executes at each document level so it becomes  
> equivalent to Sum (A1 \* B1 + A2 \* B2 + A3 \* B3 + .........+ An \* Bn)
> 
> Whereas I need ---- Sum (A) \* Sum (B)
> 
> Is there any easy way of achieving it without handling at the client level?
> 
> Thanks  
> Rahul

---

<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, 3:30am UTC](https://discuss.elastic.co/t/query-related-to-scripts-on-facets/7551/3 "2017-07-06T03:30:07Z")

</div>


