# Statistical facet for every document separately in one query

**URL:** <https://discuss.elastic.co/t/statistical-facet-for-every-document-separately-in-one-query/11311>\
**Category:** Elasticsearch\
**Created:** [March 26, 2013, 10:02am UTC](https://discuss.elastic.co/t/statistical-facet-for-every-document-separately-in-one-query/11311 "2013-03-26T10:02:01Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![waldemar](https://avatars.discourse-cdn.com/v4/letter/w/bcef8e/32.png) [@waldemar](https://discuss.elastic.co/u/waldemar)\
**Post date:** [March 26, 2013, 10:02am UTC](https://discuss.elastic.co/t/statistical-facet-for-every-document-separately-in-one-query/11311/1 "2013-03-26T10:02:01Z")

</div>

Hi to All,

Is it possible to get statistical facet for every document separately in  
one query?

For example, if I get 10 results (10 documents) then I also want to have  
calculated statistical facet for every document separately and returned all  
together (in one query).

And if so, please provide me an example.

Thanks in advance.

Thanks you all,

Waldemar

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![q42jaap](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/q42jaap/32/2241_2.png) [@q42jaap](https://discuss.elastic.co/u/q42jaap)\
**Post date:** [March 26, 2013, 2:31pm UTC](https://discuss.elastic.co/t/statistical-facet-for-every-document-separately-in-one-query/11311/2 "2013-03-26T14:31:28Z")

</div>

Hi Waldemar,

If I understand correctly, a statistical facet will show count, total, sum  
of squares, mean (average), minimum, maximum, variance, and standard  
deviation.  
For a single document these numbers will be very predictable, the count  
will be 1, the total, average, minimum, maximum will be just the value for  
the field. Variance and standard deviation will mean nothing for just 1  
number.

Why would you want this info? Do you have examples of a couple of documents  
so we can understand your use case?

Jaap Taal

[Q42 BV | tel 070 44523 42 | direct 070 44523 65 | [http://q42.nl](http://q42.nl) |  
Waldorpstraat 17F, Den Haag | Vijzelstraat 72 unit 4.23, Amsterdam | KvK  
30164662 ]

On Tue, Mar 26, 2013 at 11:02 AM, [waldemar@pureholidayhomes.com](mailto:waldemar@pureholidayhomes.com) wrote:

> Hi to All,
> 
> Is it possible to get statistical facet for every document separately in  
> one query?
> 
> For example, if I get 10 results (10 documents) then I also want to have  
> calculated statistical facet for every document separately and returned all  
> together (in one query).
> 
> And if so, please provide me an example.
> 
> Thanks in advance.
> 
> Thanks you all,
> 
> Waldemar
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![waldemar](https://avatars.discourse-cdn.com/v4/letter/w/bcef8e/32.png) [@waldemar](https://discuss.elastic.co/u/waldemar)\
**Post date:** [March 26, 2013, 2:35pm UTC](https://discuss.elastic.co/t/statistical-facet-for-every-document-separately-in-one-query/11311/3 "2013-03-26T14:35:29Z")

</div>

Hi Jaap,

I need a Min and Max from a one specific field. To be exact Its a price  
field.  
If there is a different method for getting that kind of information, then  
please inform me of it.

Thanks,  
W.

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![waldemar](https://avatars.discourse-cdn.com/v4/letter/w/bcef8e/32.png) [@waldemar](https://discuss.elastic.co/u/waldemar)\
**Post date:** [March 26, 2013, 2:37pm UTC](https://discuss.elastic.co/t/statistical-facet-for-every-document-separately-in-one-query/11311/4 "2013-03-26T14:37:49Z")

</div>

And also I have to mention that the price field is an array that contains  
multiple prices for different conditions.  
So I want a min and max from all of conditions for a single document.

Thanks,  
W.

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![q42jaap](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/q42jaap/32/2241_2.png) [@q42jaap](https://discuss.elastic.co/u/q42jaap)\
**Post date:** [March 26, 2013, 3:10pm UTC](https://discuss.elastic.co/t/statistical-facet-for-every-document-separately-in-one-query/11311/5 "2013-03-26T15:10:43Z")

</div>

I don't think the statistical facet is meant to do what you want. I doubt  
it will work correctly for repeated fields.  
I also don't think you can let Elasticsearch do this type of processing on  
the nodes. Especially because you want to restrict whatever is in the  
nested section.

What is specified in nested section can only be used to determine if the  
whole document should match or not. If you get the \_source back, you can  
post-process the prices to reflect the same restrictions as in the nested  
query.

Good luck!

Jaap Taal

[Q42 BV | tel 070 44523 42 | direct 070 44523 65 | [http://q42.nl](http://q42.nl) |  
Waldorpstraat 17F, Den Haag | Vijzelstraat 72 unit 4.23, Amsterdam | KvK  
30164662 ]

On Tue, Mar 26, 2013 at 3:37 PM, [waldemar@pureholidayhomes.com](mailto:waldemar@pureholidayhomes.com) wrote:

> And also I have to mention that the price field is an array that contains  
> multiple prices for different conditions.  
> So I want a min and max from all of conditions for a single document.
> 
> Thanks,  
> W.
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![waldemar](https://avatars.discourse-cdn.com/v4/letter/w/bcef8e/32.png) [@waldemar](https://discuss.elastic.co/u/waldemar)\
**Post date:** [March 26, 2013, 3:30pm UTC](https://discuss.elastic.co/t/statistical-facet-for-every-document-separately-in-one-query/11311/6 "2013-03-26T15:30:55Z")

</div>

I'm sorry Jaap, but you are not too helpful.  
Please be more constructive, and please reply with examples.

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 26, 2013, 3:54pm UTC](https://discuss.elastic.co/t/statistical-facet-for-every-document-separately-in-one-query/11311/7 "2013-03-26T15:54:18Z")

</div>

And why do you think you need Elasticsearch to find the min or the max in something like [1, 2, 3, 10]?  
I mean that you can handle that on your side (client side) for each doc.

What Elasticsearch can offer you is to compute that values across millions of document. For single doc, I suggest to do it on your side.

Does it help?

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 26 mars 2013 à 15:37, [waldemar@pureholidayhomes.com](mailto:waldemar@pureholidayhomes.com) a écrit :

> And also I have to mention that the price field is an array that contains multiple prices for different conditions.  
> So I want a min and max from all of conditions for a single document.
> 
> Thanks,  
> W.
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![waldemar](https://avatars.discourse-cdn.com/v4/letter/w/bcef8e/32.png) [@waldemar](https://discuss.elastic.co/u/waldemar)\
**Post date:** [March 27, 2013, 7:36am UTC](https://discuss.elastic.co/t/statistical-facet-for-every-document-separately-in-one-query/11311/8 "2013-03-27T07:36:39Z")

</div>

Hi David,

Why? Maybe because I have in that array several thousands, or even tens of  
thousands prices, and I don't want to ElasticSearch return all that data,  
especially when I need only min and max.  
So it's obvious why I don't want to do it on the client side.  
Does that make sense?

Besides, why you are asking this questions that do not relate at all to myproblem?

Best,  
Waldemar

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:44am UTC](https://discuss.elastic.co/t/statistical-facet-for-every-document-separately-in-one-query/11311/9 "2017-07-06T02:44:14Z")

</div>


