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

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