understanding-groups.asciidoc 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[rollup-understanding-groups]]
  4. == Understanding Groups
  5. experimental[]
  6. To preserve flexibility, Rollup Jobs are defined based on how future queries may need to use the data. Traditionally, systems force
  7. the admin to make decisions about what metrics to rollup and on what interval. E.g. The average of `cpu_time` on an hourly basis. This
  8. is limiting; if, at a future date, the admin wishes to see the average of `cpu_time` on an hourly basis _and partitioned by `host_name`_,
  9. they are out of luck.
  10. Of course, the admin can decide to rollup the `[hour, host]` tuple on an hourly basis, but as the number of grouping keys grows, so do the
  11. number of tuples the admin needs to configure. Furthermore, these `[hours, host]` tuples are only useful for hourly rollups... daily, weekly,
  12. or monthly rollups all require new configurations.
  13. Rather than force the admin to decide ahead of time which individual tuples should be rolled up, Elasticsearch's Rollup jobs are configured
  14. based on which groups are potentially useful to future queries. For example, this configuration:
  15. [source,js]
  16. --------------------------------------------------
  17. "groups" : {
  18. "date_histogram": {
  19. "field": "timestamp",
  20. "interval": "1h",
  21. "delay": "7d"
  22. },
  23. "terms": {
  24. "fields": ["hostname", "datacenter"]
  25. },
  26. "histogram": {
  27. "fields": ["load", "net_in", "net_out"],
  28. "interval": 5
  29. }
  30. }
  31. --------------------------------------------------
  32. // NOTCONSOLE
  33. Allows `date_histogram`'s to be used on the `"timestamp"` field, `terms` aggregations to be used on the `"hostname"` and `"datacenter"`
  34. fields, and `histograms` to be used on any of `"load"`, `"net_in"`, `"net_out"` fields.
  35. Importantly, these aggs/fields can be used in any combination. This aggregation:
  36. [source,js]
  37. --------------------------------------------------
  38. "aggs" : {
  39. "hourly": {
  40. "date_histogram": {
  41. "field": "timestamp",
  42. "interval": "1h"
  43. },
  44. "aggs": {
  45. "host_names": {
  46. "terms": {
  47. "field": "hostname"
  48. }
  49. }
  50. }
  51. }
  52. }
  53. --------------------------------------------------
  54. // NOTCONSOLE
  55. is just as valid as this aggregation:
  56. [source,js]
  57. --------------------------------------------------
  58. "aggs" : {
  59. "hourly": {
  60. "date_histogram": {
  61. "field": "timestamp",
  62. "interval": "1h"
  63. },
  64. "aggs": {
  65. "data_center": {
  66. "terms": {
  67. "field": "datacenter"
  68. }
  69. },
  70. "aggs": {
  71. "host_names": {
  72. "terms": {
  73. "field": "hostname"
  74. }
  75. },
  76. "aggs": {
  77. "load_values": {
  78. "histogram": {
  79. "field": "load",
  80. "interval": 5
  81. }
  82. }
  83. }
  84. }
  85. }
  86. }
  87. }
  88. --------------------------------------------------
  89. // NOTCONSOLE
  90. You'll notice that the second aggregation is not only substantially larger, it also swapped the position of the terms aggregation on
  91. `"hostname"`, illustrating how the order of aggregations does not matter to rollups. Similarly, while the `date_histogram` is required
  92. for rolling up data, it isn't required while querying (although often used). For example, this is a valid aggregation for
  93. Rollup Search to execute:
  94. [source,js]
  95. --------------------------------------------------
  96. "aggs" : {
  97. "host_names": {
  98. "terms": {
  99. "field": "hostname"
  100. }
  101. }
  102. }
  103. --------------------------------------------------
  104. // NOTCONSOLE
  105. Ultimately, when configuring `groups` for a job, think in terms of how you might wish to partition data in a query at a future date...
  106. then include those in the config. Because Rollup Search allows any order or combination of the grouped fields, you just need to decide
  107. if a field is useful for aggregating later, and how you might wish to use it (terms, histogram, etc)
  108. === Grouping Limitations with heterogeneous indices
  109. There was previously a limitation in how Rollup could handle indices that had heterogeneous mappings (multiple, unrelated/non-overlapping
  110. mappings). The recommendation at the time was to configure a separate job per data "type". For example, you might configure a separate
  111. job for each Beats module that you had enabled (one for `process`, another for `filesystem`, etc).
  112. This recommendation was driven by internal implementation details that caused document counts to be potentially incorrect if a single "merged"
  113. job was used.
  114. This limitation has since been alleviated. As of 6.4.0, it is now considered best practice to combine all rollup configurations
  115. into a single job.
  116. As an example, if your index has two types of documents:
  117. [source,js]
  118. --------------------------------------------------
  119. {
  120. "timestamp": 1516729294000,
  121. "temperature": 200,
  122. "voltage": 5.2,
  123. "node": "a"
  124. }
  125. --------------------------------------------------
  126. // NOTCONSOLE
  127. and
  128. [source,js]
  129. --------------------------------------------------
  130. {
  131. "timestamp": 1516729294000,
  132. "price": 123,
  133. "title": "Foo"
  134. }
  135. --------------------------------------------------
  136. // NOTCONSOLE
  137. the best practice is to combine them into a single rollup job which covers both of these document types, like this:
  138. [source,js]
  139. --------------------------------------------------
  140. PUT _xpack/rollup/job/combined
  141. {
  142. "index_pattern": "data-*",
  143. "rollup_index": "data_rollup",
  144. "cron": "*/30 * * * * ?",
  145. "page_size" :1000,
  146. "groups" : {
  147. "date_histogram": {
  148. "field": "timestamp",
  149. "interval": "1h",
  150. "delay": "7d"
  151. },
  152. "terms": {
  153. "fields": ["node", "title"]
  154. }
  155. },
  156. "metrics": [
  157. {
  158. "field": "temperature",
  159. "metrics": ["min", "max", "sum"]
  160. },
  161. {
  162. "field": "price",
  163. "metrics": ["avg"]
  164. }
  165. ]
  166. }
  167. --------------------------------------------------
  168. // NOTCONSOLE
  169. === Doc counts and overlapping jobs
  170. There was previously an issue with document counts on "overlapping" job configurations, driven by the same internal implementation detail.
  171. If there were two Rollup jobs saving to the same index, where one job is a "subset" of another job, it was possible that document counts
  172. could be incorrect for certain aggregation arrangements.
  173. This issue has also since been eliminated in 6.4.0.