stats-aggregation.asciidoc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. [[search-aggregations-matrix-stats-aggregation]]
  2. === Matrix Stats
  3. The `matrix_stats` aggregation is a numeric aggregation that computes the following statistics over a set of document fields:
  4. [horizontal]
  5. `count`:: Number of per field samples included in the calculation.
  6. `mean`:: The average value for each field.
  7. `variance`:: Per field Measurement for how spread out the samples are from the mean.
  8. `skewness`:: Per field measurement quantifying the asymmetric distribution around the mean.
  9. `kurtosis`:: Per field measurement quantifying the shape of the distribution.
  10. `covariance`:: A matrix that quantitatively describes how changes in one field are associated with another.
  11. `correlation`:: The covariance matrix scaled to a range of -1 to 1, inclusive. Describes the relationship between field
  12. distributions.
  13. The following example demonstrates the use of matrix stats to describe the relationship between income and poverty.
  14. [source,js]
  15. --------------------------------------------------
  16. {
  17. "aggs": {
  18. "matrixstats": {
  19. "matrix_stats": {
  20. "fields": ["poverty", "income"]
  21. }
  22. }
  23. }
  24. }
  25. --------------------------------------------------
  26. The aggregation type is `matrix_stats` and the `fields` setting defines the set of fields (as an array) for computing
  27. the statistics. The above request returns the following response:
  28. [source,js]
  29. --------------------------------------------------
  30. {
  31. ...
  32. "aggregations": {
  33. "matrixstats": {
  34. "fields": [{
  35. "name": "income",
  36. "count": 50,
  37. "mean": 51985.1,
  38. "variance": 7.383377037755103E7,
  39. "skewness": 0.5595114003506483,
  40. "kurtosis": 2.5692365287787124,
  41. "covariance": {
  42. "income": 7.383377037755103E7,
  43. "poverty": -21093.65836734694
  44. },
  45. "correlation": {
  46. "income": 1.0,
  47. "poverty": -0.8352655256272504
  48. }
  49. }, {
  50. "name": "poverty",
  51. "count": 50,
  52. "mean": 12.732000000000001,
  53. "variance": 8.637730612244896,
  54. "skewness": 0.4516049811903419,
  55. "kurtosis": 2.8615929677997767,
  56. "covariance": {
  57. "income": -21093.65836734694,
  58. "poverty": 8.637730612244896
  59. },
  60. "correlation": {
  61. "income": -0.8352655256272504,
  62. "poverty": 1.0
  63. }
  64. }]
  65. }
  66. }
  67. }
  68. --------------------------------------------------
  69. ==== Multi Value Fields
  70. The `matrix_stats` aggregation treats each document field as an independent sample. The `mode` parameter controls what
  71. array value the aggregation will use for array or multi-valued fields. This parameter can take one of the following:
  72. [horizontal]
  73. `avg`:: (default) Use the average of all values.
  74. `min`:: Pick the lowest value.
  75. `max`:: Pick the highest value.
  76. `sum`:: Use the sum of all values.
  77. `median`:: Use the median of all values.
  78. ==== Missing Values
  79. The `missing` parameter defines how documents that are missing a value should be treated.
  80. By default they will be ignored but it is also possible to treat them as if they had a value.
  81. This is done by adding a set of fieldname : value mappings to specify default values per field.
  82. [source,js]
  83. --------------------------------------------------
  84. {
  85. "aggs": {
  86. "matrixstats": {
  87. "matrix_stats": {
  88. "fields": ["poverty", "income"],
  89. "missing": {"income" : 50000} <1>
  90. }
  91. }
  92. }
  93. }
  94. --------------------------------------------------
  95. <1> Documents without a value in the `income` field will have the default value `50000`.
  96. ==== Script
  97. This aggregation family does not yet support scripting.