﻿---
title: Run Discover and Dashboards queries in the background
description: Send long-running Discover and dashboard queries to a background search. Keep working while they run, and open the results later.
url: https://www.elastic.co/docs/explore-analyze/discover/background-search
products:
  - Elastic Documentation
  - Kibana
applies_to:
  - Elastic Cloud Serverless: Preview
  - Elastic Stack: Preview since 9.2
---

# Run Discover and Dashboards queries in the background
If a query takes a long time to run, you can send it to the background and keep working in Kibana. When the search finishes, you can open its results from **Discover** or **Dashboards**, or manage all your background searches from one list.
<important>
  Background search is a feature introduced in version 9.2. It replaces the deprecated **Search sessions** feature.
  If you used search sessions in an earlier version and upgrade to 9.2, your search sessions aren't lost and become background searches.
</important>

![Animation that shows a query in Discover being sent to the background and then reopened from the list of background searches](https://images.contentstack.io/v3/assets/bltefdd0b53724fa2ce/bltee31dcf0d3917c75/68ecf412e5bae49d65a286ff/background-search.gif)

## Before you begin

The background searches that you run are personal and only visible by you. To use this feature, you must have the following minimum permissions:
<applies-switch>
  <applies-item title="{ serverless: preview, stack: preview 9.2+ }" applies-to="Elastic Cloud Serverless: Preview, Elastic Stack: Preview since 9.2">
    To send searches to the background, and to view and interact with the list of background searches from the **Discover** and **Dashboards** apps, you need permissions for **Discover** and **Dashboard**, and for the **Store Background search** [sub-feature](/docs/deploy-manage/users-roles/cluster-or-deployment-auth/kibana-privileges#kibana-feature-privileges). The same sub-feature gives you access to the **Background Search** page in Stack Management.
  </applies-item>

  <applies-item title="stack: ga 9.0-9.1" applies-to="Elastic Stack: Generally available from 9.0 to 9.1">
    In these versions, this feature is named **Search sessions**.
    - To save a session, you must have permissions for **Discover** and **Dashboard**, and the **Store Search Sessions** [sub-feature](/docs/deploy-manage/users-roles/cluster-or-deployment-auth/kibana-privileges#kibana-feature-privileges).
    - To view and restore a saved session, you must have access to Stack Management and the same **Store Search Sessions** sub-feature.
  </applies-item>
</applies-switch>

If you don't see the **Send to background** button, an administrator might need to turn the feature on. Refer to [Enable background searches](#enable-background-searches).

## Enable background searches

<applies-switch>
  <applies-item title="{ serverless: preview, stack: preview 9.3+ }" applies-to="Elastic Cloud Serverless: Preview, Elastic Stack: Preview since 9.3">
    This feature is enabled by default.
  </applies-item>

  <applies-item title="stack: preview =9.2" applies-to="Elastic Stack: Preview in 9.2">
    This feature is turned off by default. You can enable background searches by setting [`data.search.sessions.enabled`](https://docs-edge.elastic.dev/docs/reference/kibana/configuration-reference/search-sessions-settings) to `true` in the [`kibana.yml`](https://www.elastic.co/docs/deploy-manage/stack-settings) configuration file.
    <note>
      If you already set `data.search.sessions.enabled` to `true` before you upgrade, the setting stays in effect and background searches remain enabled.
    </note>
  </applies-item>

  <applies-item title="stack: ga 9.0-9.1" applies-to="Elastic Stack: Generally available from 9.0 to 9.1">
    This feature is named **Search sessions** and is turned off by default. If you already enabled it in a previous version, the setting stays in effect after an upgrade. You can enable search sessions by setting [`data.search.sessions.enabled`](https://docs-edge.elastic.dev/docs/reference/kibana/configuration-reference/search-sessions-settings) to `true` in the [`kibana.yml`](https://www.elastic.co/docs/deploy-manage/stack-settings) configuration file.
  </applies-item>
</applies-switch>


## Send a search to the background

You can send a search to the background only while it's running. Before the search starts, and after it completes, the **Send to background** button is unavailable.
1. Write or edit the query.
2. Start the query:
   - In ES|QL mode, select **Search**. In 9.2 and 9.3, select **Run**, or `refresh` **Refresh** if the query hasn't changed.
   - In classic mode, select **Update**, or `refresh` **Refresh** if the query hasn't changed.
   While the search runs, the `background_task` **Send to background** button becomes available next to **Cancel**.
3. Select `background_task` **Send to background**. The search is sent to the background and added to the queue of background searches.

**Result:** The search runs in the background and appears in your list of background searches. You can resume your other tasks, for example start a new search, navigate to a different application, or close the browser.
<tip applies-to="Elastic Cloud Serverless: Preview, Elastic Stack: Preview since 9.4">
  When the search completes, a notification informs you, even if you have navigated to a different application. Selecting it opens the completed search results directly.
</tip>

Background searches expire after 7 days. Beyond that period, you must run the search again. You can change this default value by editing the [`data.search.sessions.defaultExpiration`](https://docs-edge.elastic.dev/docs/reference/kibana/configuration-reference/search-sessions-settings) setting.

## Reopen, inspect, or manage background searches

Your background searches stay in a list until they expire. From the list, you can reopen a search to see its results, inspect or rename it, extend how long it's kept, or delete it.
1. Open your list of background searches using one of the following methods:
   - Once a background search is sent to the background, a notification appears to tell you, with a link to open the list of background searches.
   - If you miss the notification or need to access this list at any time, go to **Discover** or **Dashboards** and select the `background_task` **Background searches** button in the application menu. This option is only available from version 9.2.
     <tip>
     From **Discover**, you can only view Discover background searches. And from **Dashboards**, you can only see Dashboards background searches.
     </tip>
   - In Stack Management, open **Background Search**.
2. Find the background search that you want to interact with using the search or status filter options.
   - To open it to view its results and continue your explorations, select its name. Relative dates are converted to absolute dates. In **Discover**, the search opens in a new tab, which counts toward the [25-tab limit](/docs/explore-analyze/discover/work-with-tabs#open-tab).
   - To rename it, select the `boxes_horizontal` **More actions** button, then select `pencil` **Edit name**. By default, background searches get default names that indicate their execution date and time.
   - To extend its current expiration date, select the `boxes_horizontal` **More actions** button, then select **Extend**. The new expiration is one more `data.search.sessions.defaultExpiration` period, which is 7 days by default. You can extend a search only while it's running or after it completes.
   - To inspect the details of a background search, select `boxes_horizontal` **More actions**, then select `document` **Inspect**. A flyout opens showing the configuration for that background search.
     - <applies-to>Elastic Cloud Serverless: Preview</applies-to> <applies-to>Elastic Stack: Preview since 9.5</applies-to> If you inspect a search from the **Background searches** flyout in **Discover** or **Dashboards**, the details open as a child flyout.
   - To delete it, select the `boxes_horizontal` **More actions** button, then select `trash` **Delete**.

**Result:** The list reflects the change you made, or the search opens in **Discover** or **Dashboards**.
<note>
  Administrators can also see running background searches on the [Query activity](https://www.elastic.co/docs/deploy-manage/monitor/query-activity) page. While you use background search to manage your own long-running searches, Query activity provides administrators with a cluster-wide view of all running queries, with the ability to cancel any of them.
</note>


## Background search limitations in dashboards

Some visualization features don't fully support background searches. When you restore a dashboard, panels that use those features don't load right away. They send additional data requests, which can take a while, and the **Your background search is still running** warning appears. You can wait for the queries to finish, or come back to the dashboard later.
A panel behaves like this if it uses one of the following features:
**Lens**
- A **top values** dimension with an enabled **Group other values as "Other"** setting. This is configurable in the **Advanced** section of the dimension.
- An **intervals** dimension.

**Aggregation-based** visualizations
- A **terms** aggregation with an enabled **Group other values in separate bucket** setting.
- A **histogram** aggregation.

**Maps**
- Layers using joins, blended layers, or tracks layers.


## Next steps

- [How to query in Discover's ES|QL mode](https://www.elastic.co/docs/explore-analyze/discover/use-esql): Write the queries you send to the background.


## Related pages

- [How Discover works](https://www.elastic.co/docs/explore-analyze/discover/discover-get-started)
- [Query activity](https://www.elastic.co/docs/deploy-manage/monitor/query-activity)