# Accuracy in ES search

**URL:** <https://discuss.elastic.co/t/accuracy-in-es-search/147170>\
**Category:** Elasticsearch\
**Created:** [September 4, 2018, 8:42am UTC](https://discuss.elastic.co/t/accuracy-in-es-search/147170 "2018-09-04T08:42:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![JPelastic](https://avatars.discourse-cdn.com/v4/letter/j/9e8a1a/32.png) [@JPelastic](https://discuss.elastic.co/u/JPelastic)\
**Post date:** [September 4, 2018, 8:42am UTC](https://discuss.elastic.co/t/accuracy-in-es-search/147170/1 "2018-09-04T08:42:13Z")

</div>

We have a stock of about 2 million documents containing invoice information in an Elastic db.

We want to understand:

- If I do a count of documents with certain fixed properties (like terms)
- Or a sum over all those documents

Is the result we get back from Elastic exact? Or should I use the rule of thumb that anything I get out of ES has a statistical margin of error?

Another one I worry about is much more complex:

- Looking for all companies who sent only one invoice in a specific month. The list of companies should be exact… From what I got from the course, there is always some margin of error…

I’m in doubt and I can’t afford to be 😊

---

<div class="post-metadata">

**Author:** ![Yashasvi\_Raj\_Pant](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yashasvi_raj_pant/32/35022_2.png) [@Yashasvi\_Raj\_Pant](https://discuss.elastic.co/u/Yashasvi_Raj_Pant)\
**Post date:** [September 4, 2018, 9:49am UTC](https://discuss.elastic.co/t/accuracy-in-es-search/147170/2 "2018-09-04T09:49:14Z")

</div>

It actually depends on what type of aggregation you are using and in what manner. For Instance, for **terms** aggregation, you will get the exact result if you apply **"size":0** (which means to include all the keys). Also, you will get the exact value for the **sum** aggregation as well. Certain aggregations like **cardinality** are based on approximation though.

For the second answer, You can get the exact list of companies listing the companies with **terms** aggregation and setting **"size":0**.  
For the monthly breakdown, you can use the Histogram aggregation of the date field and use **terms** of the company as the sub-aggregation.

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [September 4, 2018, 10:07pm UTC](https://discuss.elastic.co/t/accuracy-in-es-search/147170/3 "2018-09-04T22:07:54Z")

</div>

Size = 0 won’t work for very high cardinality terms. You may need to look at the ‘composite’ agg or partitioning with the terms agg

---

<div class="post-metadata">

**Author:** ![Yashasvi\_Raj\_Pant](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yashasvi_raj_pant/32/35022_2.png) [@Yashasvi\_Raj\_Pant](https://discuss.elastic.co/u/Yashasvi_Raj_Pant)\
**Post date:** [September 5, 2018, 4:04am UTC](https://discuss.elastic.co/t/accuracy-in-es-search/147170/4 "2018-09-05T04:04:40Z")

</div>

Also, found that "size":0 on terms is not supported from anymore from ES-5.0 onward. You have to explicitly specify the maximum size if you have the idea of it.

---

<div class="post-metadata">

**Author:** ![JPelastic](https://avatars.discourse-cdn.com/v4/letter/j/9e8a1a/32.png) [@JPelastic](https://discuss.elastic.co/u/JPelastic)\
**Post date:** [September 5, 2018, 5:55am UTC](https://discuss.elastic.co/t/accuracy-in-es-search/147170/5 "2018-09-05T05:55:55Z")

</div>

Would using the other techniques give me 100% surety that I got all the documents? or would there still be a margin of error?

Thank you both for your answers!

---

<div class="post-metadata">

**Author:** ![Yashasvi\_Raj\_Pant](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yashasvi_raj_pant/32/35022_2.png) [@Yashasvi\_Raj\_Pant](https://discuss.elastic.co/u/Yashasvi_Raj_Pant)\
**Post date:** [September 5, 2018, 3:27pm UTC](https://discuss.elastic.co/t/accuracy-in-es-search/147170/6 "2018-09-05T15:27:02Z")

</div>

Composite aggregation or partitioning with the terms aggregation could give you 100% accurate value if you use them in correct way. Refer to their document for their detail implementation. Also, note that Composite aggregation is the new feature in elasticsearch-6 and still in beta phase.

If you are using older version of Elasticsearch(less than 5.0), then you can use "size":0, if your terms count is less than Integer.MAX\_VALUE.

---

<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:** [October 3, 2018, 3:27pm UTC](https://discuss.elastic.co/t/accuracy-in-es-search/147170/7 "2018-10-03T15:27:05Z")

</div>

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