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

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