You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Returns the value at which a certain percentage of observed values occur. For example, the 95th percentile is the value which is greater than 95% of the observed values and the 50th percentile is the `MEDIAN`.
16
-
17
-
**Supported types**
18
-
19
-
| number | percentile | result |
20
-
| --- | --- | --- |
21
-
| double | double | double |
22
-
| double | integer | double |
23
-
| double | long | double |
24
-
| integer | double | double |
25
-
| integer | integer | double |
26
-
| integer | long | double |
27
-
| long | double | double |
28
-
| long | integer | double |
29
-
| long | long | double |
30
-
31
-
**Examples**
32
-
33
-
```esql
34
-
FROM employees
35
-
| STATS p0 = PERCENTILE(salary, 0)
36
-
, p50 = PERCENTILE(salary, 50)
37
-
, p99 = PERCENTILE(salary, 99)
38
-
```
39
-
40
-
| p0:double| p50:double| p99:double|
41
-
| --- | --- | --- |
42
-
| 25324 | 47003 | 74970.29 |
43
-
44
-
The expression can use inline functions. For example, to calculate a percentile of the maximum values of a multivalued column, first use `MV_MAX` to get the maximum value per row, and use the result with the `PERCENTILE` function
### `PERCENTILE` is (usually) approximate [esql-percentile-approximate]
57
-
58
1
There are many different algorithms to calculate percentiles. The naive implementation simply stores all the values in a sorted array. To find the 50th percentile, you simply find the value that is at `my_array[count(my_array) * 0.5]`.
59
2
60
3
Clearly, the naive implementation does not scale — the sorted array grows linearly with the number of values in your dataset. To calculate percentiles across potentially billions of values in an Elasticsearch cluster, *approximate* percentiles are calculated.
@@ -72,11 +15,3 @@ The following chart shows the relative error on a uniform distribution depending
It shows how precision is better for extreme percentiles. The reason why error diminishes for large number of values is that the law of large numbers makes the distribution of values more and more uniform and the t-digest tree can do a better job at summarizing it. It would not be the case on more skewed distributions.
75
-
76
-
::::{warning}
77
-
`PERCENTILE` is also [non-deterministic](https://en.wikipedia.org/wiki/Nondeterministic_algorithm). This means you can get slightly different results using the same data.
Copy file name to clipboardExpand all lines: docs/reference/data-analysis/aggregations/search-aggregations-metrics-cardinality-aggregation.md
+2-13Lines changed: 2 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -65,19 +65,8 @@ Computing exact counts requires loading values into a hash set and returning its
65
65
66
66
This `cardinality` aggregation is based on the [HyperLogLog++](https://static.googleusercontent.com/media/research.google.com/fr//pubs/archive/40671.pdf) algorithm, which counts based on the hashes of the values with some interesting properties:
67
67
68
-
* configurable precision, which decides on how to trade memory for accuracy,
69
-
* excellent accuracy on low-cardinality sets,
70
-
* fixed memory usage: no matter if there are tens or billions of unique values, memory usage only depends on the configured precision.
71
-
72
-
For a precision threshold of `c`, the implementation that we are using requires about `c * 8` bytes.
73
-
74
-
The following chart shows how the error varies before and after the threshold:
For all 3 thresholds, counts have been accurate up to the configured threshold. Although not guaranteed, this is likely to be the case. Accuracy in practice depends on the dataset in question. In general, most datasets show consistently good accuracy. Also note that even with a threshold as low as 100, the error remains very low (1-6% as seen in the above graph) even when counting millions of items.
79
-
80
-
The HyperLogLog++ algorithm depends on the leading zeros of hashed values, the exact distributions of hashes in a dataset can affect the accuracy of the cardinality.
Copy file name to clipboardExpand all lines: docs/reference/data-analysis/aggregations/search-aggregations-metrics-percentile-aggregation.md
+2-19Lines changed: 2 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -175,31 +175,14 @@ GET latency/_search
175
175
176
176
## Percentiles are (usually) approximate [search-aggregations-metrics-percentile-aggregation-approximation]
177
177
178
-
There are many different algorithms to calculate percentiles. The naive implementation simply stores all the values in a sorted array. To find the 50th percentile, you simply find the value that is at `my_array[count(my_array) * 0.5]`.
179
-
180
-
Clearly, the naive implementation does not scale — the sorted array grows linearly with the number of values in your dataset. To calculate percentiles across potentially billions of values in an Elasticsearch cluster, *approximate* percentiles are calculated.
181
-
182
-
The algorithm used by the `percentile` metric is called TDigest (introduced by Ted Dunning in [Computing Accurate Quantiles using T-Digests](https://github.com/tdunning/t-digest/blob/master/docs/t-digest-paper/histo.pdf)).
183
-
184
-
When using this metric, there are a few guidelines to keep in mind:
185
-
186
-
* Accuracy is proportional to `q(1-q)`. This means that extreme percentiles (e.g. 99%) are more accurate than less extreme percentiles, such as the median
187
-
* For small sets of values, percentiles are highly accurate (and potentially 100% accurate if the data is small enough).
188
-
* As the quantity of values in a bucket grows, the algorithm begins to approximate the percentiles. It is effectively trading accuracy for memory savings. The exact level of inaccuracy is difficult to generalize, since it depends on your data distribution and volume of data being aggregated
189
-
190
-
The following chart shows the relative error on a uniform distribution depending on the number of collected values and the requested percentile:
It shows how precision is better for extreme percentiles. The reason why error diminishes for large number of values is that the law of large numbers makes the distribution of values more and more uniform and the t-digest tree can do a better job at summarizing it. It would not be the case on more skewed distributions.
Percentile aggregations are also [non-deterministic](https://en.wikipedia.org/wiki/Nondeterministic_algorithm). This means you can get slightly different results using the same data.
: (Optional, float) Only applicable to `int8_hnsw`, `int4_hnsw`, `int8_flat`, and `int4_flat` index types. The confidence interval to use when quantizing the vectors. Can be any value between and including `0.90` and `1.0` or exactly `0`. When the value is `0`, this indicates that dynamic quantiles should be calculated for optimized quantization. When between `0.90` and `1.0`, this value restricts the values used when calculating the quantization thresholds. For example, a value of `0.95` will only use the middle 95% of the values when calculating the quantization thresholds (e.g. the highest and lowest 2.5% of values will be ignored). Defaults to `1/(dims + 1)` for `int8` quantized vectors and `0` for `int4` for dynamic quantile calculation.
289
289
290
+
`rescore_vector`
291
+
: (Optional, object) Functionality in [preview]. An optional section that configures automatic vector rescoring on knn queries for the given field. Only applicable to quantized index types.
292
+
:::::{dropdown} Properties of `rescore_vector`
293
+
`oversample`
294
+
: (required, float) The amount to oversample the search results by. This value should be greater than `1.0` and less than `10.0`. The higher the value, the more vectors will be gathered and rescored with the raw values per shard.
295
+
: In case a knn query specifies a `rescore_vector` parameter, the query `rescore_vector` parameter will be used instead.
296
+
: See [oversampling and rescoring quantized vectors](docs-content://solutions/search/vector/knn.md#dense-vector-knn-search-rescoring) for details.
0 commit comments