Matrix stats aggregations

The matrix_stats aggregation generates advanced stats for multiple fields in a matrix form. The following example returns advanced stats in a matrix form for the taxful_total_price and products.base_price fields:

  1. GET opensearch_dashboards_sample_data_ecommerce/_search
  2. {
  3. "size": 0,
  4. "aggs": {
  5. "matrix_stats_taxful_total_price": {
  6. "matrix_stats": {
  7. "fields": ["taxful_total_price", "products.base_price"]
  8. }
  9. }
  10. }
  11. }

copy

Example response

  1. ...
  2. "aggregations" : {
  3. "matrix_stats_taxful_total_price" : {
  4. "doc_count" : 4675,
  5. "fields" : [
  6. {
  7. "name" : "products.base_price",
  8. "count" : 4675,
  9. "mean" : 34.994239430147196,
  10. "variance" : 360.5035285833703,
  11. "skewness" : 5.530161335032702,
  12. "kurtosis" : 131.16306324042148,
  13. "covariance" : {
  14. "products.base_price" : 360.5035285833703,
  15. "taxful_total_price" : 846.6489362233166
  16. },
  17. "correlation" : {
  18. "products.base_price" : 1.0,
  19. "taxful_total_price" : 0.8444765264325268
  20. }
  21. },
  22. {
  23. "name" : "taxful_total_price",
  24. "count" : 4675,
  25. "mean" : 75.05542864304839,
  26. "variance" : 2788.1879749835402,
  27. "skewness" : 15.812149139924037,
  28. "kurtosis" : 619.1235507385902,
  29. "covariance" : {
  30. "products.base_price" : 846.6489362233166,
  31. "taxful_total_price" : 2788.1879749835402
  32. },
  33. "correlation" : {
  34. "products.base_price" : 0.8444765264325268,
  35. "taxful_total_price" : 1.0
  36. }
  37. }
  38. ]
  39. }
  40. }
  41. }

The following table lists all response fields.

StatisticDescription
countThe number of samples measured.
meanThe average value of the field measured from the sample.
varianceHow far the values of the field measured are spread out from its mean value. The larger the variance, the more it’s spread from its mean value.
skewnessAn asymmetric measure of the distribution of the field’s values around the mean.
kurtosisA measure of the tail heaviness of a distribution. As the tail becomes lighter, kurtosis decreases. As the tail becomes heavier, kurtosis increases. To learn about kurtosis, see Wikipedia.
covarianceA measure of the joint variability between two fields. A positive value means their values move in the same direction and the other way around.
correlationA measure of the strength of the relationship between two fields. The valid values are between [-1, 1]. A value of -1 means that the value is negatively correlated and a value of 1 means that it’s positively correlated. A value of 0 means that there’s no identifiable relationship between them.