1
0

bucket-count-ks-test-aggregation.asciidoc 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. [role="xpack"]
  2. [[search-aggregations-bucket-count-ks-test-aggregation]]
  3. === Bucket count K-S test correlation aggregation
  4. ++++
  5. <titleabbrev>Bucket count K-S test</titleabbrev>
  6. ++++
  7. A sibling pipeline aggregation which executes a two sample Kolmogorov–Smirnov test
  8. (referred to as a "K-S test" from now on) against a provided distribution, and the
  9. distribution implied by the documents counts in the configured sibling aggregation.
  10. Specifically, for some metric, assuming that the percentile intervals of the metric are
  11. known beforehand or have been computed by an aggregation, then one would use range
  12. aggregation for the sibling to compute the p-value of the distribution difference between
  13. the metric and the restriction of that metric to a subset of the documents. A natural use
  14. case is if the sibling aggregation range aggregation nested in a terms aggregation, in
  15. which case one compares the overall distribution of metric to its restriction to each term.
  16. [[bucket-count-ks-test-agg-syntax]]
  17. ==== Parameters
  18. `buckets_path`::
  19. (Required, string)
  20. Path to the buckets that contain one set of values to correlate. Must be a `_count` path
  21. For syntax, see <<buckets-path-syntax>>.
  22. `alternative`::
  23. (Optional, list)
  24. A list of string values indicating which K-S test alternative to calculate.
  25. The valid values are: "greater", "less", "two_sided". This parameter is key for
  26. determining the K-S statistic used when calculating the K-S test. Default value is
  27. all possible alternative hypotheses.
  28. `fractions`::
  29. (Optional, list)
  30. A list of doubles indicating the distribution of the samples with which to compare to the
  31. `buckets_path` results. In typical usage this is the overall proportion of documents in
  32. each bucket, which is compared with the actual document proportions in each bucket
  33. from the sibling aggregation counts. The default is to assume that overall documents
  34. are uniformly distributed on these buckets, which they would be if one used equal
  35. percentiles of a metric to define the bucket end points.
  36. `sampling_method`::
  37. (Optional, string)
  38. Indicates the sampling methodology when calculating the K-S test. Note, this is sampling
  39. of the returned values. This determines the cumulative distribution function (CDF) points
  40. used comparing the two samples. Default is `upper_tail`, which emphasizes the upper
  41. end of the CDF points. Valid options are: `upper_tail`, `uniform`, and `lower_tail`.
  42. ==== Syntax
  43. A `bucket_count_ks_test` aggregation looks like this in isolation:
  44. [source,js]
  45. --------------------------------------------------
  46. {
  47. "bucket_count_ks_test": {
  48. "buckets_path": "range_values>_count", <1>
  49. "alternative": ["less", "greater", "two_sided"], <2>
  50. "sampling_method": "upper_tail" <3>
  51. }
  52. }
  53. --------------------------------------------------
  54. // NOTCONSOLE
  55. <1> The buckets containing the values to test against.
  56. <2> The alternatives to calculate.
  57. <3> The sampling method for the K-S statistic.
  58. [[bucket-count-ks-test-agg-example]]
  59. ==== Example
  60. The following snippet runs the `bucket_count_ks_test` on the individual terms in the field `version` against a uniform distribution.
  61. The uniform distribution reflects the `latency` percentile buckets. Not shown is the pre-calculation of the `latency` indicator values,
  62. which was done utilizing the
  63. <<search-aggregations-metrics-percentile-aggregation,percentiles>> aggregation.
  64. This example is only using the deciles of `latency`.
  65. [source,console]
  66. -------------------------------------------------
  67. POST correlate_latency/_search?size=0&filter_path=aggregations
  68. {
  69. "aggs": {
  70. "buckets": {
  71. "terms": { <1>
  72. "field": "version",
  73. "size": 2
  74. },
  75. "aggs": {
  76. "latency_ranges": {
  77. "range": { <2>
  78. "field": "latency",
  79. "ranges": [
  80. { "to": 0 },
  81. { "from": 0, "to": 105 },
  82. { "from": 105, "to": 225 },
  83. { "from": 225, "to": 445 },
  84. { "from": 445, "to": 665 },
  85. { "from": 665, "to": 885 },
  86. { "from": 885, "to": 1115 },
  87. { "from": 1115, "to": 1335 },
  88. { "from": 1335, "to": 1555 },
  89. { "from": 1555, "to": 1775 },
  90. { "from": 1775 }
  91. ]
  92. }
  93. },
  94. "ks_test": { <3>
  95. "bucket_count_ks_test": {
  96. "buckets_path": "latency_ranges>_count",
  97. "alternative": ["less", "greater", "two_sided"]
  98. }
  99. }
  100. }
  101. }
  102. }
  103. }
  104. -------------------------------------------------
  105. // TEST[setup:correlate_latency]
  106. <1> The term buckets containing a range aggregation and the bucket correlation aggregation. Both are utilized to calculate
  107. the correlation of the term values with the latency.
  108. <2> The range aggregation on the latency field. The ranges were created referencing the percentiles of the latency field.
  109. <3> The bucket count K-S test aggregation that tests if the bucket counts comes from the same distribution as `fractions`;
  110. where `fractions` is a uniform distribution.
  111. And the following may be the response:
  112. [source,console-result]
  113. ----
  114. {
  115. "aggregations" : {
  116. "buckets" : {
  117. "doc_count_error_upper_bound" : 0,
  118. "sum_other_doc_count" : 0,
  119. "buckets" : [
  120. {
  121. "key" : "1.0",
  122. "doc_count" : 100,
  123. "latency_ranges" : {
  124. "buckets" : [
  125. {
  126. "key" : "*-0.0",
  127. "to" : 0.0,
  128. "doc_count" : 0
  129. },
  130. {
  131. "key" : "0.0-105.0",
  132. "from" : 0.0,
  133. "to" : 105.0,
  134. "doc_count" : 1
  135. },
  136. {
  137. "key" : "105.0-225.0",
  138. "from" : 105.0,
  139. "to" : 225.0,
  140. "doc_count" : 9
  141. },
  142. {
  143. "key" : "225.0-445.0",
  144. "from" : 225.0,
  145. "to" : 445.0,
  146. "doc_count" : 0
  147. },
  148. {
  149. "key" : "445.0-665.0",
  150. "from" : 445.0,
  151. "to" : 665.0,
  152. "doc_count" : 0
  153. },
  154. {
  155. "key" : "665.0-885.0",
  156. "from" : 665.0,
  157. "to" : 885.0,
  158. "doc_count" : 0
  159. },
  160. {
  161. "key" : "885.0-1115.0",
  162. "from" : 885.0,
  163. "to" : 1115.0,
  164. "doc_count" : 10
  165. },
  166. {
  167. "key" : "1115.0-1335.0",
  168. "from" : 1115.0,
  169. "to" : 1335.0,
  170. "doc_count" : 20
  171. },
  172. {
  173. "key" : "1335.0-1555.0",
  174. "from" : 1335.0,
  175. "to" : 1555.0,
  176. "doc_count" : 20
  177. },
  178. {
  179. "key" : "1555.0-1775.0",
  180. "from" : 1555.0,
  181. "to" : 1775.0,
  182. "doc_count" : 20
  183. },
  184. {
  185. "key" : "1775.0-*",
  186. "from" : 1775.0,
  187. "doc_count" : 20
  188. }
  189. ]
  190. },
  191. "ks_test" : {
  192. "less" : 2.248673241788478E-4,
  193. "greater" : 1.0,
  194. "two_sided" : 5.791639181800257E-4
  195. }
  196. },
  197. {
  198. "key" : "2.0",
  199. "doc_count" : 100,
  200. "latency_ranges" : {
  201. "buckets" : [
  202. {
  203. "key" : "*-0.0",
  204. "to" : 0.0,
  205. "doc_count" : 0
  206. },
  207. {
  208. "key" : "0.0-105.0",
  209. "from" : 0.0,
  210. "to" : 105.0,
  211. "doc_count" : 19
  212. },
  213. {
  214. "key" : "105.0-225.0",
  215. "from" : 105.0,
  216. "to" : 225.0,
  217. "doc_count" : 11
  218. },
  219. {
  220. "key" : "225.0-445.0",
  221. "from" : 225.0,
  222. "to" : 445.0,
  223. "doc_count" : 20
  224. },
  225. {
  226. "key" : "445.0-665.0",
  227. "from" : 445.0,
  228. "to" : 665.0,
  229. "doc_count" : 20
  230. },
  231. {
  232. "key" : "665.0-885.0",
  233. "from" : 665.0,
  234. "to" : 885.0,
  235. "doc_count" : 20
  236. },
  237. {
  238. "key" : "885.0-1115.0",
  239. "from" : 885.0,
  240. "to" : 1115.0,
  241. "doc_count" : 10
  242. },
  243. {
  244. "key" : "1115.0-1335.0",
  245. "from" : 1115.0,
  246. "to" : 1335.0,
  247. "doc_count" : 0
  248. },
  249. {
  250. "key" : "1335.0-1555.0",
  251. "from" : 1335.0,
  252. "to" : 1555.0,
  253. "doc_count" : 0
  254. },
  255. {
  256. "key" : "1555.0-1775.0",
  257. "from" : 1555.0,
  258. "to" : 1775.0,
  259. "doc_count" : 0
  260. },
  261. {
  262. "key" : "1775.0-*",
  263. "from" : 1775.0,
  264. "doc_count" : 0
  265. }
  266. ]
  267. },
  268. "ks_test" : {
  269. "less" : 0.9642895789647244,
  270. "greater" : 4.58718174664754E-9,
  271. "two_sided" : 5.916656831139733E-9
  272. }
  273. }
  274. ]
  275. }
  276. }
  277. }
  278. ----