Skip to content

Commit 8846ffd

Browse files
jrodewigabprash
andauthored
[DOCS] Remove approximate document counts example from term agg docs (#55442)
Removes an example from the "Document counts are approximate" section of the terms agg documentation. As #52377 details, the example was no longer accurate in 7.x or 6.8. Document counts were more precise than the example presented. We've opened issue #56025 to discuss re-adding an example later. Co-authored-by: James Rodewig <[email protected]> Co-authored-by: AB Prashanth <[email protected]>
1 parent cfd61e6 commit 8846ffd

File tree

1 file changed

+12
-146
lines changed

1 file changed

+12
-146
lines changed

docs/reference/aggregations/bucket/terms-aggregation.asciidoc

Lines changed: 12 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ GET /_search
6666
--------------------------------------------------
6767
// TEST[s/_search/_search\?filter_path=aggregations/]
6868

69-
<1> `terms` aggregation should be a field of type `keyword` or any other data type suitable for bucket aggregations. In order to use it with `text` you will need to enable
69+
<1> `terms` aggregation should be a field of type `keyword` or any other data type suitable for bucket aggregations. In order to use it with `text` you will need to enable
7070
<<fielddata, fielddata>>.
7171

7272
Response:
@@ -124,84 +124,10 @@ NOTE: If you want to retrieve **all** terms or all combinations of terms in a ne
124124
[[search-aggregations-bucket-terms-aggregation-approximate-counts]]
125125
==== Document counts are approximate
126126

127-
As described above, the document counts (and the results of any sub aggregations) in the terms aggregation are not always
128-
accurate. This is because each shard provides its own view of what the ordered list of terms should be and these are
129-
combined to give a final view. Consider the following scenario:
130-
131-
A request is made to obtain the top 5 terms in the field product, ordered by descending document count from an index with
132-
3 shards. In this case each shard is asked to give its top 5 terms.
133-
134-
[source,console]
135-
--------------------------------------------------
136-
GET /_search
137-
{
138-
"aggs" : {
139-
"products" : {
140-
"terms" : {
141-
"field" : "product",
142-
"size" : 5
143-
}
144-
}
145-
}
146-
}
147-
--------------------------------------------------
148-
// TEST[s/_search/_search\?filter_path=aggregations/]
149-
150-
The terms for each of the three shards are shown below with their
151-
respective document counts in brackets:
152-
153-
[width="100%",cols="^2,^2,^2,^2",options="header"]
154-
|=========================================================
155-
| | Shard A | Shard B | Shard C
156-
157-
| 1 | Product A (25) | Product A (30) | Product A (45)
158-
| 2 | Product B (18) | Product B (25) | Product C (44)
159-
| 3 | Product C (6) | Product F (17) | Product Z (36)
160-
| 4 | Product D (3) | Product Z (16) | Product G (30)
161-
| 5 | Product E (2) | Product G (15) | Product E (29)
162-
| 6 | Product F (2) | Product H (14) | Product H (28)
163-
| 7 | Product G (2) | Product I (10) | Product Q (2)
164-
| 8 | Product H (2) | Product Q (6) | Product D (1)
165-
| 9 | Product I (1) | Product J (6) |
166-
| 10 | Product J (1) | Product C (4) |
167-
168-
|=========================================================
169-
170-
The shards will return their top 5 terms so the results from the shards will be:
171-
172-
[width="100%",cols="^2,^2,^2,^2",options="header"]
173-
|=========================================================
174-
| | Shard A | Shard B | Shard C
175-
176-
| 1 | Product A (25) | Product A (30) | Product A (45)
177-
| 2 | Product B (18) | Product B (25) | Product C (44)
178-
| 3 | Product C (6) | Product F (17) | Product Z (36)
179-
| 4 | Product D (3) | Product Z (16) | Product G (30)
180-
| 5 | Product E (2) | Product G (15) | Product E (29)
181-
182-
|=========================================================
183-
184-
Taking the top 5 results from each of the shards (as requested) and combining them to make a final top 5 list produces
185-
the following:
186-
187-
[width="40%",cols="^2,^2"]
188-
|=========================================================
189-
190-
| 1 | Product A (100)
191-
| 2 | Product Z (52)
192-
| 3 | Product C (50)
193-
| 4 | Product G (45)
194-
| 5 | Product B (43)
195-
196-
|=========================================================
197-
198-
Because Product A was returned from all shards we know that its document count value is accurate. Product C was only
199-
returned by shards A and C so its document count is shown as 50 but this is not an accurate count. Product C exists on
200-
shard B, but its count of 4 was not high enough to put Product C into the top 5 list for that shard. Product Z was also
201-
returned only by 2 shards but the third shard does not contain the term. There is no way of knowing, at the point of
202-
combining the results to produce the final list of terms, that there is an error in the document count for Product C and
203-
not for Product Z. Product H has a document count of 44 across all 3 shards but was not included in the final list of
204-
terms because it did not make it into the top five terms on any of the shards.
127+
Document counts (and the results of any sub aggregations) in the terms
128+
aggregation are not always accurate. Each shard provides its own view of what
129+
the ordered list of terms should be. These views are combined to give a final
130+
view.
205131

206132
==== Shard Size
207133

@@ -226,35 +152,7 @@ The default `shard_size` is `(size * 1.5 + 10)`.
226152

227153
There are two error values which can be shown on the terms aggregation. The first gives a value for the aggregation as
228154
a whole which represents the maximum potential document count for a term which did not make it into the final list of
229-
terms. This is calculated as the sum of the document count from the last term returned from each shard. For the example
230-
given above the value would be 46 (2 + 15 + 29). This means that in the worst case scenario a term which was not returned
231-
could have the 4th highest document count.
232-
233-
[source,console-result]
234-
--------------------------------------------------
235-
{
236-
...
237-
"aggregations" : {
238-
"products" : {
239-
"doc_count_error_upper_bound" : 46,
240-
"sum_other_doc_count" : 79,
241-
"buckets" : [
242-
{
243-
"key" : "Product A",
244-
"doc_count" : 100
245-
},
246-
{
247-
"key" : "Product Z",
248-
"doc_count" : 52
249-
}
250-
...
251-
]
252-
}
253-
}
254-
}
255-
--------------------------------------------------
256-
// TESTRESPONSE[s/\.\.\.//]
257-
// TESTRESPONSE[s/: (\-)?[0-9]+/: $body.$_path/]
155+
terms. This is calculated as the sum of the document count from the last term returned from each shard.
258156

259157
==== Per bucket document count error
260158

@@ -280,39 +178,7 @@ GET /_search
280178

281179
This shows an error value for each term returned by the aggregation which represents the 'worst case' error in the document count
282180
and can be useful when deciding on a value for the `shard_size` parameter. This is calculated by summing the document counts for
283-
the last term returned by all shards which did not return the term. In the example above the error in the document count for Product C
284-
would be 15 as Shard B was the only shard not to return the term and the document count of the last term it did return was 15.
285-
The actual document count of Product C was 54 so the document count was only actually off by 4 even though the worst case was that
286-
it would be off by 15. Product A, however has an error of 0 for its document count, since every shard returned it we can be confident
287-
that the count returned is accurate.
288-
289-
[source,console-result]
290-
--------------------------------------------------
291-
{
292-
...
293-
"aggregations" : {
294-
"products" : {
295-
"doc_count_error_upper_bound" : 46,
296-
"sum_other_doc_count" : 79,
297-
"buckets" : [
298-
{
299-
"key" : "Product A",
300-
"doc_count" : 100,
301-
"doc_count_error_upper_bound" : 0
302-
},
303-
{
304-
"key" : "Product Z",
305-
"doc_count" : 52,
306-
"doc_count_error_upper_bound" : 2
307-
}
308-
...
309-
]
310-
}
311-
}
312-
}
313-
--------------------------------------------------
314-
// TESTRESPONSE[s/\.\.\.//]
315-
// TESTRESPONSE[s/: (\-)?[0-9]+/: $body.$_path/]
181+
the last term returned by all shards which did not return the term.
316182

317183
These errors can only be calculated in this way when the terms are ordered by descending document count. When the aggregation is
318184
ordered by the terms values themselves (either ascending or descending) there is no error in the document count since if a shard
@@ -673,7 +539,7 @@ GET /_search
673539

674540
===== Filtering Values with partitions
675541

676-
Sometimes there are too many unique terms to process in a single request/response pair so
542+
Sometimes there are too many unique terms to process in a single request/response pair so
677543
it can be useful to break the analysis up into multiple requests.
678544
This can be achieved by grouping the field's values into a number of partitions at query-time and processing
679545
only one partition in each request.
@@ -712,10 +578,10 @@ GET /_search
712578
This request is finding the last logged access date for a subset of customer accounts because we
713579
might want to expire some customer accounts who haven't been seen for a long while.
714580
The `num_partitions` setting has requested that the unique account_ids are organized evenly into twenty
715-
partitions (0 to 19). and the `partition` setting in this request filters to only consider account_ids falling
581+
partitions (0 to 19). and the `partition` setting in this request filters to only consider account_ids falling
716582
into partition 0. Subsequent requests should ask for partitions 1 then 2 etc to complete the expired-account analysis.
717583

718-
Note that the `size` setting for the number of results returned needs to be tuned with the `num_partitions`.
584+
Note that the `size` setting for the number of results returned needs to be tuned with the `num_partitions`.
719585
For this particular account-expiration example the process for balancing values for `size` and `num_partitions` would be as follows:
720586

721587
1. Use the `cardinality` aggregation to estimate the total number of unique account_id values
@@ -724,8 +590,8 @@ For this particular account-expiration example the process for balancing values
724590
4. Run a test request
725591

726592
If we have a circuit-breaker error we are trying to do too much in one request and must increase `num_partitions`.
727-
If the request was successful but the last account ID in the date-sorted test response was still an account we might want to
728-
expire then we may be missing accounts of interest and have set our numbers too low. We must either
593+
If the request was successful but the last account ID in the date-sorted test response was still an account we might want to
594+
expire then we may be missing accounts of interest and have set our numbers too low. We must either
729595

730596
* increase the `size` parameter to return more results per partition (could be heavy on memory) or
731597
* increase the `num_partitions` to consider less accounts per request (could increase overall processing time as we need to make more requests)

0 commit comments

Comments
 (0)