Run a pattern analysis on your log data in Discover

If your logs are free-form messages, pattern analysis groups similar messages into patterns, so you can see which ones are common, filter out the noise, and focus on unusual messages while you troubleshoot. For each pattern, Discover shows how its messages are distributed over time in a chart, and gives example documents.

  • Make sure Discover is in classic mode. ES|QL mode doesn't have the Patterns view. To switch, refer to Switch to Discover's classic mode.
  • Pattern analysis is available in Elasticsearch, Observability Complete, and Security projects. It's not available in Observability Logs Essentials projects.
  • You need a Platinum or higher subscription or an active trial. Pattern analysis groups messages with the categorize text aggregation, which requires it.
  • Discover must have a data view selected that has a time field and contains a text field, and a time range that contains data.
  • This example uses the web logs sample data. To follow along, add it and select its data view, or use your own log data.
Tip

In ES|QL mode, you can group similar messages in a query.

  1. Go to Discover.

  2. Expand the data view menu, and select Kibana Sample Data Logs.

  3. If you don't see any results, expand the time range, for example, to Last 7 days.

  4. Select Patterns (or View as → Patterns, depending on your version). Discover groups the messages of a text field into patterns and lists them with the chart.

    Patterns view in Discover listing the patterns found in the log messages, with the View as menu open
  5. Optional: To analyze a different text field, change the field in the field selector.

  6. Optional: To calculate patterns over a longer period than the time range you set in step 3, select the Options button to open the Pattern analysis settings, and set the Minimum time range. A longer range improves accuracy. The list still shows the patterns for the time range you set in step 3.

  7. Optional: To focus on specific messages, select one or more patterns, and then select Filter for patterns in Discover. To hide the messages that match them instead, select Filter out patterns in Discover.

Result: Discover shows the patterns in your log messages. After you filter, the table shows only the documents that match the patterns you kept, or only the ones that don't match the patterns you filtered out.

If a text value in your results, such as a log message, looks unusual, you can check how common it is without running a pattern analysis on the whole list first. Discover shows the pattern the value follows, the other documents that match it, and when they occurred. You can then open those documents or filter them out.

The Find similar values button appears only for text fields, such as message or error.message, in a data view that has a time field. In the Summary column, which gives an overview of each result, Find similar values also appears, and it analyzes the message of the document. For example, it uses message, error.message, or event.original, depending on which of these fields the document has.

The button has the same subscription and project requirements as pattern analysis. Refer to Before you begin.

  1. In classic mode, run a query that returns log messages. For example, select Kibana Sample Data Logs and expand the time range if the table is empty.

  2. In the table, hover over a value in a text field column, such as message, and select Find similar values.

  3. In the flyout, read the pattern that the value follows, the number of documents that match it, and the chart that shows when they occurred. The table in the flyout lists up to 1,000 of the matching documents, and the count covers all matching documents, not only a sample. The analysis uses the query, filters, and time range of your table.

    Similar values flyout in classic mode, with the pattern of a message, the chart and table of matching documents, and the sampling button
  4. Optional: To balance speed and accuracy, select the sampling button at the top of the flyout. It reads Auto sampling by default, which sets the share of documents to analyze for you. To choose the share yourself, set Random sampling to On - manual, enter a Sampling percentage between 0.001 and 50, and select Apply. A lower percentage is faster but less accurate. To analyze every document, set Random sampling to Off.

  5. Optional: To keep working with these documents, select Open documents in Discover to see only the documents that match the pattern. To see everything else instead, select Filter out documents in Discover.

Result: The flyout shows how common the value is and when it occurred. If you select one of the buttons in step 5, Discover opens a new tab, labeled Pattern followed by the field name, with your query and filters plus a filter that keeps or excludes the matching documents. Your original tab stays as it was.

In ES|QL mode, refer to Work with ES|QL results in Discover > Find similar messages in the table.

To find unusual behavior in a pattern, create a categorization anomaly detection job from the Patterns view. This needs permission to create anomaly detection jobs, and Discover doesn't show the button without it.