﻿---
title: Run a pattern analysis on your log data in Discover
description: Group similar log messages into patterns in Discover, or check how common one message is, to filter out noise and find unusual messages.
url: https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9535/explore-analyze/discover/run-pattern-analysis-discover
products:
  - Elastic Documentation
  - Kibana
applies_to:
  - Elastic Cloud Serverless: Generally available
  - Elastic Stack: Generally available
---

# 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.

## Before you begin

- 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](/elastic/docs-content/pull/9535/explore-analyze/discover/switch-esql-mode#revert-to-classic-mode).
- <applies-to>Elastic Cloud Serverless: Generally available</applies-to> Pattern analysis is available in Elasticsearch, Observability Complete, and Security projects. It's not available in Observability Logs Essentials projects.
- <applies-to>Elastic Stack: Generally available</applies-to> You need a [Platinum or higher subscription](https://www.elastic.co/subscriptions) or an active trial. Pattern analysis groups messages with the [categorize text aggregation](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/tree/main/reference/aggregations/search-aggregations-bucket-categorize-text-aggregation), which requires it.
- **Discover** must have a [data view](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9535/explore-analyze/find-and-organize/data-views) 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](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9535/manage-data/ingest/sample-data). To follow along, add it and select its data view, or use your own log data.

<tip applies-to="Elastic Cloud Serverless: Preview, Elastic Stack: Preview since 9.4">
  In ES|QL mode, you can [group similar messages in a query](/elastic/docs-content/pull/9535/explore-analyze/discover/inspect-grouped-stats#pattern-rendering).
</tip>


## Run a pattern analysis

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](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9535/explore-analyze/images/kibana-log-pattern-analysis-results.png)
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 `controls` **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.

## Find similar messages in the table

<applies-to>
  - Elastic Cloud Serverless: Generally available
  - Elastic Stack: Planned
</applies-to>

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](#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](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9535/explore-analyze/images/kibana-discover-find-similar-values-classic.png)
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](/elastic/docs-content/pull/9535/explore-analyze/discover/esql-results#find-similar-values-esql).

## Next steps

To find unusual behavior in a pattern, create a [categorization anomaly detection job](/elastic/docs-content/pull/9535/explore-analyze/machine-learning/anomaly-detection/ml-configuring-categories#creating-categorization-jobs) from the **Patterns** view. This needs permission to create anomaly detection jobs, and **Discover** doesn't show the button without it.

## Related pages

- [How to query in Discover's classic mode](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9535/explore-analyze/discover/use-classic-mode)
- [Search and filter with KQL, Lucene, and filters in Discover's classic mode](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9535/explore-analyze/discover/search-and-filter-classic)