You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/en/observability/logs-stream.asciidoc
+40-47Lines changed: 40 additions & 47 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -165,7 +165,7 @@ POST logs-example-default/_doc
165
165
}
166
166
----
167
167
168
-
The previous command stores the document in `logs-example-default`. You can retrieve it with the following search:
168
+
The previous command stores the document in `logs-example-default`. Retrieve it with the following search:
169
169
170
170
[source,console]
171
171
----
@@ -194,7 +194,7 @@ You see something like this:
194
194
}
195
195
----
196
196
197
-
{es} indexes the `message` field by default. This means you can search for phrases like `WARN` or `Disk usage exceeds`, but you can't use the `message` field for sorting or filtering. The following command searches for `WARN` and shows the document as result.
197
+
{es} indexes the `message` field by default meaning you can search for phrases like `WARN` or `Disk usage exceeds`. For example, the following command searches for the phrase `WARN` in the log `message` field:
198
198
199
199
[source,console]
200
200
----
@@ -210,7 +210,7 @@ GET logs-example-default/_search
210
210
}
211
211
----
212
212
213
-
Your message, however, contains all of the following potential fields. Extracting these will allow you to filter and aggregate based on these fields:
213
+
While you can search for phrases in the `message` field, you can't use this field to filter log data. Your message, however, contains all of the following potential fields you can extract and use to filter and aggregate your log data:
214
214
215
215
- *@timestamp* – `2023-08-08T13:45:12.123Z` – Extracting this field lets you sort logs by date and time. This is helpful when you want to view your logs in the order that they occurred or identify when issues happened.
216
216
- *log.level* – `WARN` – Extracting this field lets you filter logs by severity. This is helpful if you want to focus on high-severity WARN or ERROR-level logs, and reduce noise by filtering out low-severity INFO-level logs.
@@ -223,7 +223,7 @@ NOTE: These fields are part of the {ecs-ref}/ecs-reference.html[Elastic Common S
223
223
[[logs-stream-extract-timestamp]]
224
224
== Extract the `@timestamp` field
225
225
226
-
When you ingested the document in the previous section, you'll notice the `@timestamp` field in the resulting document shows when you added the data to {es}, not when the log occurred:
226
+
When you ingested the document in the previous section, you'll notice the `@timestamp` field shows when you added the data to {es}, not when the log occurred:
227
227
228
228
[source,JSON]
229
229
----
@@ -235,29 +235,24 @@ When you ingested the document in the previous section, you'll notice the `@time
235
235
...
236
236
----
237
237
238
-
This section shows you how to extract the `@timestamp` field from the example log so you can filter by when logs occurred and when issues happened.
238
+
This section shows you how to extract the `@timestamp` field from the log message so you can filter by when the logs and issues actually occurred.
239
239
240
-
[source,log]
241
-
----
242
-
2023-08-08T13:45:12.123Z WARN 192.168.1.101 Disk usage exceeds 90%.
243
-
----
244
-
245
-
To extract the timestamp you need to:
240
+
To extract the timestamp, you need to:
246
241
247
-
- <<logs-stream-ingest-pipeline>>
248
-
- <<logs-stream-simulate-api>>
249
-
- <<logs-stream-index-template>>
250
-
- <<logs-stream-create-data-stream>>
242
+
. <<logs-stream-ingest-pipeline>>
243
+
. <<logs-stream-simulate-api>>
244
+
. <<logs-stream-index-template>>
245
+
. <<logs-stream-create-data-stream>>
251
246
252
247
[discrete]
253
248
[[logs-stream-ingest-pipeline]]
254
249
=== Use an ingest pipeline to extract the `@timestamp`
255
250
256
-
To extract the `@timestamp` field from the example log, use an ingest pipeline with a dissect processor. Ingest pipelines in {es} are used to process incoming documents. The {ref}/dissect-processor.html[dissect processor] is one of the available processors that extracts structured fields from your unstructured log message based the pattern you set. In the following example command, the dissect processor extracts the timestamp to the `@timestamp` field.
251
+
Ingest pipelines consist of a series of processors that perform common transformations on incoming documents before they are indexed. To extract the `@timestamp` field from the example log, use an ingest pipeline with a dissect processor. The {ref}/dissect-processor.html[dissect processor] extracts structured fields from unstructured log messages based on a pattern you set.
257
252
258
-
{es} can parse string timestamps that are in `yyyy-MM-dd'T'HH:mm:ss.SSSZ` and `yyyy-MM-dd` formats into date fields. Since the log example's timestamp is in one of these formats, you don't need additional processors. If your log timestamps are more complex or use a nonstandard format, you need a {ref}/date-processor.html[date processor] to parse the timestamp into a date field. You can also use a date processor to set the timezone, change the target field, and change the output format of the timestamp.
253
+
{es} can parse string timestamps that are in `yyyy-MM-dd'T'HH:mm:ss.SSSZ` and `yyyy-MM-dd` formats into date fields. Since the log example's timestamp is in one of these formats, you don't need additional processors. More complex or nonstandard timestamps require a {ref}/date-processor.html[date processor] to parse the timestamp into a date field. Date processors can also set the timezone, change the target field, and change the output format of the timestamp.
259
254
260
-
This command creates an ingest pipeline with a dissect processor:
255
+
In the following command, the dissect processor extracts the timestamp from the `message` field to the `@timestamp` field and leaves the rest of the message in the `message` field:
261
256
262
257
[source,console]
263
258
----
@@ -275,16 +270,17 @@ PUT _ingest/pipeline/logs-example-default
275
270
}
276
271
----
277
272
278
-
Set these values for your pipeline:
273
+
The previous command sets the following values for your ingest pipeline:
274
+
279
275
- `_ingest/pipeline/logs-example-default` – The name of the pipeline,`logs-example-default`, needs to match the name of your data stream. You'll set up your data stream in the next section. See the {fleet-guide}/data-streams.html#data-streams-naming-scheme[data stream naming scheme] for more information.
280
276
- `field` – The field you're extracting data from, `message` in this case.
281
-
- `pattern`– The pattern of the elements in your log data. The following pattern extracts the timestamp, `2023-08-08T13:45:12.123Z`, to the `@timestamp` field, while the rest of the message, `WARN 192.168.1.101 Disk usage exceeds 90%.`, stays in the `message` field. This works because the dissect processor looks for the space as a separator defined by the pattern `%{timestamp} %{message}`.
277
+
- `pattern`– The pattern of the elements in your log data. The following pattern extracts the timestamp, `2023-08-08T13:45:12.123Z`, to the `@timestamp` field, while the rest of the message, `WARN 192.168.1.101 Disk usage exceeds 90%.`, stays in the `message` field. The dissect processor looks for the space as a separator defined by the pattern `%{timestamp} %{message}`.
282
278
283
279
[discrete]
284
280
[[logs-stream-simulate-api]]
285
281
=== Test your pipeline with the simulate pipeline API
286
282
287
-
You can test that your ingest pipeline works as expected with the {ref}/simulate-pipeline-api.html#ingest-verbose-param[simulate pipeline API]. This runs the pipeline without storing any documents, and is great for testing your pipeline with different documents. Run this command to test your pipeline:
283
+
The {ref}/simulate-pipeline-api.html#ingest-verbose-param[simulate pipeline API]runs the ingest pipeline without storing any documents. This lets you verify your pipeline works using multiple documents. Run the following command to test your ingest pipeline with the simulate pipeline API.
288
284
289
285
[source,console]
290
286
----
@@ -322,7 +318,7 @@ The results should show the `@timestamp` field extracted from the `message` fiel
322
318
}
323
319
----
324
320
325
-
NOTE: Create the index pipeline using the `PUT` command in the previous section before using the simulate pipeline API.
321
+
NOTE: Make sure you've created the index pipeline using the `PUT` command in the previous section before using the simulate pipeline API.
326
322
327
323
[discrete]
328
324
[[logs-stream-index-template]]
@@ -352,15 +348,13 @@ PUT _index_template/logs-example-default-template
352
348
}
353
349
----
354
350
355
-
356
-
357
-
Set the following values for the index template:
351
+
The previous command sets the following values for your index template:
358
352
359
353
- `index_patterns`– The index pattern needs to match your log data stream. Naming conventions for data streams are `<type>-<dataset>-<namespace>`. In this example, your logs data stream is named `logs-example-default`. Data that matches this pattern will go through your pipeline.
360
354
- `data_stream` – Enables data streams.
361
-
- `priority` – Index templates with higher priority take precedence over lower priority. If a data stream matches multiple index templates, the template with the higher priority is used. Built-in templates have a priority of `200`, so we recommend a priority higher than `200`.
355
+
- `priority` – Index templates with higher priority take precedence over lower priority. If a data stream matches multiple index templates, {es} uses the template with the higher priority. Built-in templates have a priority of `200`, so use a priority higher than `200` for custom templates.
362
356
- `index.default_pipeline` – The name of your ingest pipeline. `logs-example-default` in this case.
363
-
- `composed_of` – Here you can set component templates. Component templates are building blocks for constructing index templates that specify index mappings, settings, and aliases. Elastic has several built-in templates that help when ingesting your data. See the following list for more information.
357
+
- `composed_of` – Here you can set component templates. Component templates are building blocks for constructing index templates that specify index mappings, settings, and aliases. Elastic has several built-in templates that help when ingesting your data.
364
358
365
359
The component templates that are set in the previous index template are defined as follows:
366
360
@@ -378,7 +372,7 @@ The component templates that are set in the previous index template are defined
378
372
[[logs-stream-create-data-stream]]
379
373
=== Create your data stream
380
374
381
-
Create your data stream using the {fleet-guide}/data-streams.html#data-streams-naming-scheme[data stream naming scheme]. The name needs to match the name of your pipeline. For this example, we'll name the data stream `logs-example-default` and use the example log:
375
+
Create your data stream using the {fleet-guide}/data-streams.html#data-streams-naming-scheme[data stream naming scheme]. Since The name needs to match the name of your pipeline, name the data stream `logs-example-default`. Post the example log to your data stream with this command:
382
376
383
377
[source,console]
384
378
----
@@ -388,14 +382,14 @@ POST logs-example-default/_doc
388
382
}
389
383
----
390
384
391
-
Now look at your document's details using this command:
385
+
View your documents using this command:
392
386
393
387
[source,console]
394
388
----
395
389
GET /logs-example-default/_search
396
390
----
397
391
398
-
You can see the pipeline extracted the `@timestamp` field:
392
+
You should see the pipeline has extracted the `@timestamp` field:
399
393
400
394
[source,JSON]
401
395
----
@@ -426,9 +420,9 @@ You can now use the `@timestamp` field to sort your logs by the date and time th
426
420
[[logs-stream-timestamp-troubleshooting]]
427
421
=== Troubleshoot your `@timestamp` field
428
422
429
-
Check the following common issues for possible solutions:
423
+
Check the following common issues and solutions with timestamps:
430
424
431
-
- *Timestamp failure* – If your data has inconsistent date formats, you can set `ignore_failure` to `true` for your date processor. This processes logs with correctly formatted dates and ignores those with issues.
425
+
- *Timestamp failure* – If your data has inconsistent date formats, set `ignore_failure` to `true` for your date processor. This processes logs with correctly formatted dates and ignores those with issues.
432
426
- *Incorrect timezone* – Set your timezone using the `timezone` option on the {ref}/date-processor.html[date processor].
433
427
- *Incorrect timestamp format* – Your timestamp can be a Java time pattern or one of the following formats: ISO8601, UNIX, UNIX_MS, or TAI64N. See the {ref}/mapping-date-format.html[mapping date format] for more information on timestamp formats.
434
428
@@ -477,7 +471,7 @@ Now your pipeline will extract these fields:
477
471
- The `log.level` field – `WARN`
478
472
- The `message` field – `192.168.1.101 Disk usage exceeds 90%.`
479
473
480
-
After creating your pipeline, an index template points your log data to your pipeline. You can use the index template you created in the <<logs-stream-index-template, Extract the `@timestamp` field>> section.
474
+
After creating your pipeline, an index template points your log data to your pipeline. Use the index template you created in the <<logs-stream-index-template, Extract the `@timestamp` field>> section.
481
475
482
476
[discrete]
483
477
[[logs-stream-log-level-simulate]]
@@ -608,12 +602,11 @@ You should see the following results showing only your high-severity logs:
608
602
}
609
603
----
610
604
611
-
612
605
[discrete]
613
606
[[logs-stream-extract-host-ip]]
614
607
== Extract the `host.ip` field
615
608
616
-
Extracting the `host.ip` field lets you filter logs by host IP addresses. This way you can focus on specific hosts that you’re having issues with or find disparities between hosts.
609
+
Extracting the `host.ip` field lets you filter logs by host IP addresses allowing you to focus on specific hosts that you’re having issues with or find disparities between hosts.
617
610
618
611
The `host.ip` field is part of the {ecs-ref}/ecs-reference.html[Elastic Common Schema (ECS)]. Through the ECS, the `host.ip` field is mapped as an {ref}/ip.html[`ip` field type]. `ip` field types allow range queries so you can find logs with IP addresses in a specific range. You can also query `ip` field types using CIDR notation to find logs from a particular network or subnet.
619
612
@@ -662,7 +655,7 @@ Your pipeline will extract these fields:
662
655
- The `host.ip` field – `192.168.1.101`
663
656
- The `message` field – `Disk usage exceeds 90%.`
664
657
665
-
After creating your pipeline, an index template points your log data to your pipeline. You can use the index template you created in the <<logs-stream-index-template, Extract the `@timestamp` field>> section.
658
+
After creating your pipeline, an index template points your log data to your pipeline. Use the index template you created in the <<logs-stream-index-template, Extract the `@timestamp` field>> section.
666
659
667
660
[discrete]
668
661
[[logs-stream-host-ip-simulate]]
@@ -684,7 +677,7 @@ POST _ingest/pipeline/logs-example-default/_simulate
684
677
}
685
678
----
686
679
687
-
The results should show the `@timestamp`, `log.level`, and `host.ip` fields extracted from the `message` field:
680
+
The results should show the `host.ip`, `@timestamp`, and `log.level` fields extracted from the `message` field:
688
681
689
682
[source,JSON]
690
683
----
@@ -714,7 +707,7 @@ The results should show the `@timestamp`, `log.level`, and `host.ip` fields extr
714
707
[[logs-stream-host-ip-query]]
715
708
=== Query logs based on `host.ip`
716
709
717
-
You can query your logs based on the `host.ip` field in different ways. The following sections detail querying your logs using CIDR notation and range queries.
710
+
You can query your logs based on the `host.ip` field in different ways, including using CIDR notation and range queries.
718
711
719
712
Before querying your logs, add them to your data stream using this command:
720
713
@@ -827,7 +820,7 @@ Because all of the example logs are in this range, you'll get the following resu
827
820
[[logs-stream-range-query]]
828
821
==== Range queries
829
822
830
-
You can use {ref}/query-dsl-range-query.html[range queries] to query logs in a specific range.
823
+
Use {ref}/query-dsl-range-query.html[range queries] to query logs in a specific range.
831
824
832
825
The following command searches for IP addresses greater than or equal to `192.168.1.100` and less than or equal to `192.168.1.102`.
833
826
@@ -894,7 +887,7 @@ You'll get the following results matching the range you've set:
894
887
[[logs-stream-ip-ignore-malformed]]
895
888
=== Ignore malformed IP addresses
896
889
897
-
When you're ingesting a large batch of log data, a single malformed IP address can cause the entire batch to fail. You can prevent this by setting `ignore_malformed` to `true` for the `host.ip` field. Update the `host.ip` field to ignore malformed IPs using the {ref}/indices-put-mapping.html[update mapping API]:
890
+
When you're ingesting a large batch of log data, a single malformed IP address can cause the entire batch to fail. Prevent this by setting `ignore_malformed` to `true` for the `host.ip` field. Update the `host.ip` field to ignore malformed IPs using the {ref}/indices-put-mapping.html[update mapping API]:
898
891
899
892
[source,console]
900
893
----
@@ -915,9 +908,9 @@ PUT /logs-example-default/_mapping
915
908
916
909
preview::[]
917
910
918
-
By default, an ingest pipeline sends your log data to a single data stream. To simplify log data management, you can use a {ref}/reroute-processor.html[reroute processor] to route data from the generic data stream to a target data stream. For example, you might want to send high-severity logs to a specific data stream that's different from low-severity logs to help with categorization.
911
+
By default, an ingest pipeline sends your log data to a single data stream. To simplify log data management, use a {ref}/reroute-processor.html[reroute processor] to route data from the generic data stream to a target data stream. For example, you might want to send high-severity logs to a specific data stream to help with categorization.
919
912
920
-
This section shows you how to use a reroute processor to send the high-severity logs (`WARN` or `ERROR`) from the following log examples to a specific data stream and keep regular logs (`DEBUG` and `INFO`) in the default data stream:
913
+
This section shows you how to use a reroute processor to send the high-severity logs (`WARN` or `ERROR`) from the following example logs to a specific data stream and keep the regular logs (`DEBUG` and `INFO`) in the default data stream:
921
914
922
915
[source,log]
923
916
----
@@ -939,7 +932,7 @@ To use a reroute processor:
939
932
[[logs-stream-reroute-pipeline]]
940
933
=== Add a reroute processor to your ingest pipeline
941
934
942
-
You can add a reroute processor to your ingest pipeline with the following command:
935
+
Add a reroute processor to your ingest pipeline with the following command:
943
936
944
937
[source,console]
945
938
----
@@ -962,13 +955,13 @@ PUT _ingest/pipeline/logs-example-default
962
955
}
963
956
----
964
957
965
-
Set these values for the reroute processor:
958
+
The previous command sets the following values for your reroute processor:
966
959
967
-
- `tag` – Identifier for the processor that you can use for debugging and metrics. In the example, that tag is set to `high_severity_logs`.
968
-
- `if` – Conditionally runs the processor. In the example, ` "if" : "$('log.level', '') == 'WARN' || $('log.level', '') == 'ERROR'"` means the processor runs when the `log.level` field is `WARN` or `ERROR`.
960
+
- `tag` – Identifier for the processor that you can use for debugging and metrics. In the example, the tag is set to `high_severity_logs`.
961
+
- `if` – Conditionally runs the processor. In the example, `"ctx.log?.level== 'WARN' || ctx.log?.level== 'ERROR'",` means the processor runs when the `log.level` field is `WARN` or `ERROR`.
969
962
- `dataset` – the data stream dataset to route your document to if the previous condition is `true`. In the example, logs with a `log.level` of `WARN` or `ERROR` are routed to the `logs-critical-default` data stream.
970
963
971
-
After creating your pipeline, an index template points your log data to your pipeline. You can use the index template you created in the <<logs-stream-index-template, Extract the `@timestamp` field>> section.
964
+
After creating your pipeline, an index template points your log data to your pipeline. Use the index template you created in the <<logs-stream-index-template, Extract the `@timestamp` field>> section.
0 commit comments