﻿---
title: Sort Discover results by relevance
description: Sort results by relevance score in Discover to see the documents that best match your query first, in classic mode or with an ES|QL query.
url: https://www.elastic.co/docs/explore-analyze/discover/discover-search-for-relevance
products:
  - Elastic Documentation
  - Kibana
applies_to:
  - Elastic Cloud Serverless: Generally available
  - Elastic Stack: Generally available
---

# Sort Discover results by relevance
Elasticsearch gives each document a relevance score based on how well it matches your query. In **Discover**, you can sort by this score to see the best matches first.

## Before you begin

Open **Discover**.

## Sort by relevance score

The steps differ by mode, so select the tab for the mode you use.
<tab-set>
  <tab-item title="ES|QL mode">
    This example uses the [web logs sample data](https://www.elastic.co/docs/manage-data/ingest/sample-data), or you can use your own data.
    1. In **Discover**, make sure you're in ES|QL mode. If **Discover** opens in classic mode, refer to [Switch between ES|QL and classic mode](/docs/explore-analyze/discover/switch-esql-mode#switch-discover-query-mode).
    2. To get scores, add `METADATA _score` to the `FROM` command, and match text with a full-text function such as `MATCH`. Then sort by `_score`. For the sample data, enter:
       ```esql
       FROM kibana_sample_data_logs METADATA _score
       | WHERE MATCH(message, "Mozilla")
       | SORT _score DESC
       | KEEP _score, message
       | LIMIT 10
       ```
    3. If you don't see any results, expand the [time range](https://www.elastic.co/docs/explore-analyze/query-filter/filtering), for example to **Last 7 days**.
    **Result:** The table lists the best matches first, with their scores in the `_score` column.
    <tip>
      Very small scores show as `0` in the table. To see the difference between them, multiply the score in your query. For example, add `| EVAL score_x100000 = _score * 100000` before `KEEP`, then add `score_x100000` to the `KEEP` command.
    </tip>
    For more about scores, refer to [Relevance scoring](/docs/solutions/search/esql-for-search#esql-for-search-scoring) and to the [`_score` metadata field](https://docs-demo.elastic.dev/docs/reference/query-languages/esql/esql-metadata-fields).
  </tab-item>

  <tab-item title="Classic mode">
    This example uses the [flights sample data](https://www.elastic.co/docs/manage-data/ingest/sample-data), or you can use your own data.
    1. In **Discover**, if it opens in ES|QL mode, [switch to classic mode](/docs/explore-analyze/discover/switch-esql-mode#revert-to-classic-mode). Then, from the data view menu, select the data that you want to work with.
       For the flights sample data, set the data view to **Kibana Sample Data Flights**.
    2. Run your search. For the sample data, try:
       ```ts
       Warsaw OR Venice OR Clear
       ```
    3. If you don't see any results, expand the [time range](https://www.elastic.co/docs/explore-analyze/query-filter/filtering), for example to **Last 7 days**.
    4. In the fields list in the sidebar, expand the **Meta fields** list. Next to `_score`, select `plus` (**Add "_score" field**) to add it as a column.
    5. Optional: Add any other fields you want to the document table.
    6. By default, the table sorts by the time field of your data view, which is `timestamp` in the flights sample data. To turn off that sorting, select the **field sorted** option, and then select **Clear sorting**.
    7. Open the **Pick fields to sort by** menu, and then select **_score**.
    8. Select **High-Low**.
       ![Field sorting menu with _score selected and High-Low chosen](https://www.elastic.co/docs/explore-analyze/images/kibana-field-sorting-popover.png)
    **Result:** The table sorts documents from most to least relevant.
    ![Documents are sorted from most relevant to least relevant.](https://www.elastic.co/docs/explore-analyze/images/kibana-discover-search-for-relevance.png)
  </tab-item>
</tab-set>


## Related pages

- [How to query in Discover's classic mode](https://www.elastic.co/docs/explore-analyze/discover/use-classic-mode)
- [Search and filter with KQL, Lucene, and filters in Discover's classic mode](https://www.elastic.co/docs/explore-analyze/discover/search-and-filter-classic)
- [ES|QL for search](https://www.elastic.co/docs/solutions/search/esql-for-search)