use-elasticsearch-for-time-series-data.asciidoc 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. [[use-elasticsearch-for-time-series-data]]
  2. == Use {es} for time series data
  3. {es} offers features to help you store, manage, and search time series data,
  4. such as logs and metrics. Once in {es}, you can analyze and visualize your data
  5. using {kib} and other {stack} features.
  6. [discrete]
  7. [[set-up-data-tiers]]
  8. === Set up data tiers
  9. {es}'s <<index-lifecycle-management,{ilm-init}>> feature uses <<data-tiers,data
  10. tiers>> to automatically move older data to nodes with less expensive hardware
  11. as it ages. This helps improve performance and reduce storage costs.
  12. The hot and content tiers are required. The warm, cold, and frozen tiers are
  13. optional.
  14. Use high-performance nodes in the hot and warm tiers for faster
  15. indexing and faster searches on your most recent data. Use slower, less
  16. expensive nodes in the cold and frozen tiers to reduce costs.
  17. The content tier is not typically used for time series data. However, it's
  18. required to create system indices and other indices that aren't part of a data
  19. stream.
  20. The steps for setting up data tiers vary based on your deployment type:
  21. include::{es-repo-dir}/tab-widgets/data-tiers-widget.asciidoc[]
  22. [discrete]
  23. [[register-snapshot-repository]]
  24. === Register a snapshot repository
  25. The cold and frozen tiers can use <<searchable-snapshots,{search-snaps}>> to
  26. reduce local storage costs.
  27. To use {search-snaps}, you must register a supported snapshot repository. The
  28. steps for registering this repository vary based on your deployment type and
  29. storage provider:
  30. include::{es-repo-dir}/tab-widgets/snapshot-repo-widget.asciidoc[]
  31. [discrete]
  32. [[create-edit-index-lifecycle-policy]]
  33. === Create or edit an index lifecycle policy
  34. A <<data-streams,data stream>> stores your data across multiple backing
  35. indices. {ilm-init} uses an <<ilm-index-lifecycle,index lifecycle policy>> to
  36. automatically move these indices through your data tiers.
  37. If you use {fleet} or {agent}, edit one of {es}'s built-in lifecycle policies.
  38. If you use a custom application, create your own policy. In either case,
  39. ensure your policy:
  40. * Includes a phase for each data tier you've configured.
  41. * Calculates the threshold, or `min_age`, for phase transition from rollover.
  42. * Uses {search-snaps} in the cold and frozen phases, if wanted.
  43. * Includes a delete phase, if needed.
  44. include::{es-repo-dir}/tab-widgets/ilm-widget.asciidoc[]
  45. [discrete]
  46. [[create-ts-component-templates]]
  47. === Create component templates
  48. TIP: If you use {fleet} or {agent}, skip to <<search-visualize-your-data>>.
  49. {fleet} and {agent} use built-in templates to create data streams for you.
  50. If you use a custom application, you need to set up your own data stream.
  51. include::{es-repo-dir}/data-streams/set-up-a-data-stream.asciidoc[tag=ds-create-component-templates]
  52. [discrete]
  53. [[create-ts-index-template]]
  54. === Create an index template
  55. include::{es-repo-dir}/data-streams/set-up-a-data-stream.asciidoc[tag=ds-create-index-template]
  56. [discrete]
  57. [[add-data-to-data-stream]]
  58. === Add data to a data stream
  59. include::{es-repo-dir}/data-streams/set-up-a-data-stream.asciidoc[tag=ds-create-data-stream]
  60. [discrete]
  61. [[search-visualize-your-data]]
  62. === Search and visualize your data
  63. To explore and search your data in {kib}, open the main menu and select
  64. **Discover**. See {kib}'s {kibana-ref}/discover.html[Discover documentation].
  65. Use {kib}'s **Dashboard** feature to visualize your data in a chart, table, map,
  66. and more. See {kib}'s {kibana-ref}/dashboard.html[Dashboard documentation].
  67. You can also search and aggregate your data using the <<search-search,search
  68. API>>. Use <<runtime-search-request,runtime fields>> and <<grok,grok
  69. patterns>> to dynamically extract data from log messages and other unstructured
  70. content at search time.
  71. [source,console]
  72. ----
  73. GET my-data-stream/_search
  74. {
  75. "runtime_mappings": {
  76. "source.ip": {
  77. "type": "ip",
  78. "script": """
  79. String sourceip=grok('%{IPORHOST:sourceip} .*').extract(doc[ "message" ].value)?.sourceip;
  80. if (sourceip != null) emit(sourceip);
  81. """
  82. }
  83. },
  84. "query": {
  85. "bool": {
  86. "filter": [
  87. {
  88. "range": {
  89. "@timestamp": {
  90. "gte": "now-1d/d",
  91. "lt": "now/d"
  92. }
  93. }
  94. },
  95. {
  96. "range": {
  97. "source.ip": {
  98. "gte": "192.0.2.0",
  99. "lte": "192.0.2.255"
  100. }
  101. }
  102. }
  103. ]
  104. }
  105. },
  106. "fields": [
  107. "*"
  108. ],
  109. "_source": false,
  110. "sort": [
  111. {
  112. "@timestamp": "desc"
  113. },
  114. {
  115. "source.ip": "desc"
  116. }
  117. ]
  118. }
  119. ----
  120. // TEST[setup:my_data_stream]
  121. // TEST[teardown:data_stream_cleanup]
  122. {es} searches are synchronous by default. Searches across frozen data, long time
  123. ranges, or large datasets may take longer. Use the <<submit-async-search,async
  124. search API>> to run searches in the background. For more search options, see
  125. <<search-your-data>>.
  126. [source,console]
  127. ----
  128. POST my-data-stream/_async_search
  129. {
  130. "runtime_mappings": {
  131. "source.ip": {
  132. "type": "ip",
  133. "script": """
  134. String sourceip=grok('%{IPORHOST:sourceip} .*').extract(doc[ "message" ].value)?.sourceip;
  135. if (sourceip != null) emit(sourceip);
  136. """
  137. }
  138. },
  139. "query": {
  140. "bool": {
  141. "filter": [
  142. {
  143. "range": {
  144. "@timestamp": {
  145. "gte": "now-2y/d",
  146. "lt": "now/d"
  147. }
  148. }
  149. },
  150. {
  151. "range": {
  152. "source.ip": {
  153. "gte": "192.0.2.0",
  154. "lte": "192.0.2.255"
  155. }
  156. }
  157. }
  158. ]
  159. }
  160. },
  161. "fields": [
  162. "*"
  163. ],
  164. "_source": false,
  165. "sort": [
  166. {
  167. "@timestamp": "desc"
  168. },
  169. {
  170. "source.ip": "desc"
  171. }
  172. ]
  173. }
  174. ----
  175. // TEST[setup:my_data_stream]
  176. // TEST[teardown:data_stream_cleanup]