﻿---
title: Create and manage datasets with the Elasticsearch API
description: Create, get, list, and delete ES|QL Data Federation datasets with the /_query/dataset API.
url: https://www.elastic.co/elastic/docs-builder/docs/5113/reference/query-languages/esql/esql-data-federation-manage-datasets-api
products:
  - Elasticsearch
applies_to:
  - Elastic Cloud Serverless: Preview
  - Elastic Stack: Experimental in 9.5
---

# Create and manage datasets with the Elasticsearch API
Datasets are managed under the `/_query/dataset` endpoint. All dataset operations require the index `manage` privilege on the dataset name, or a fine-grained dataset privilege. Refer to [manage credentials and privileges](https://www.elastic.co/elastic/docs-builder/docs/5113/reference/query-languages/esql/esql-data-federation-security) for details.

| Operation                                                                         | Endpoint                             | API reference                                                                                                               |
|-----------------------------------------------------------------------------------|--------------------------------------|-----------------------------------------------------------------------------------------------------------------------------|
| [Create or update](#create-or-update-a-dataset)                                   | `PUT /_query/dataset/{name}`         | [Create or update an ES|QL dataset](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-esql-put-dataset) |
| [Get](#get-a-dataset)                                                             | `GET /_query/dataset/{name}`         | [Get ES|QL datasets](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-esql-get-dataset)                |
| [List all](#list-all-datasets)                                                    | `GET /_query/dataset`                | [Get ES|QL datasets](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-esql-get-dataset)                |
| [Open](#close-or-open-a-dataset) <applies-to>Elastic Stack: Planned</applies-to>  | `POST /_query/dataset/{name}/_open`  | Open an ES|QL dataset                                                                                                       |
| [Close](#close-or-open-a-dataset) <applies-to>Elastic Stack: Planned</applies-to> | `POST /_query/dataset/{name}/_close` | Close an ES|QL dataset                                                                                                      |
| [Delete](#delete-a-dataset)                                                       | `DELETE /_query/dataset/{name}`      | [Delete ES|QL datasets](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-esql-delete-dataset)          |

This page is a quick reference for each operation. For the complete request and response details, follow the API reference links in the table.

## Create or update a dataset

[`PUT /_query/dataset/{name}`](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-esql-put-dataset) creates a new dataset or replaces an existing one entirely.
A dataset cannot have the same name as an existing index, data stream, alias, or view, because dataset names share the same namespace. Dataset names must be lowercase and cannot begin with `-`, `_`, or `+`.
The optional `description` can be at most 1,000 characters long.
<applies-to>Elastic Stack: Planned</applies-to> <applies-to>Elastic Cloud Serverless: Preview</applies-to> For restrictions on S3 bucket names, aliases, and Amazon Resource Names (ARNs), refer to [Amazon S3 resource restrictions](/elastic/docs-builder/docs/5113/reference/query-languages/esql/esql-data-federation-patterns#s3-resource-requirements).
<tab-set>
  <tab-item title="Console">
    ```console
    PUT /_query/dataset/access_logs
    {
      "data_source": "prod_s3_logs",
      "resource": "s3://logs-bucket/access/**/*.parquet",
      "description": "Production access logs",
      "settings": {
        "partition_detection": "hive"
      }
    }
    ```
  </tab-item>

  <tab-item title="curl">
    ```bash
    curl -X PUT "${ELASTICSEARCH_URL}/_query/dataset/access_logs" \
      -H "Authorization: ApiKey ${API_KEY}" \
      -H "Content-Type: application/json" \
      -d '{
      "data_source": "prod_s3_logs",
      "resource": "s3://logs-bucket/access/**/*.parquet",
      "description": "Production access logs",
      "settings": {
        "partition_detection": "hive"
      }
    }'
    ```
  </tab-item>
</tab-set>


### Setting validation

<applies-to>
  - Elastic Stack: Planned
</applies-to>

Elasticsearch validates setting values when you register the dataset, rather than waiting until the first query. A value that isn't supported, such as a multi-character `delimiter`, an unknown `encoding`, or a `segment_size` below the minimum, returns a `400` error that identifies the setting.
<note>
  Datasets registered before this validation was introduced continue to work without being revalidated. Replacing one of these datasets triggers validation, so correct any unsupported values in the replacement request.
</note>


### Verify the inferred schema

After creating a dataset, verify the inferred schema by [checking its field mappings](/elastic/docs-builder/docs/5113/reference/query-languages/esql/esql-data-federation-quickstart#check-field-mappings).

## Get a dataset

[`GET /_query/dataset/{name}`](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-esql-get-dataset) retrieves a dataset by name.
<tab-set>
  <tab-item title="Console">
    ```console
    GET /_query/dataset/access_logs
    ```
  </tab-item>

  <tab-item title="curl">
    ```bash
    curl -X GET "${ELASTICSEARCH_URL}/_query/dataset/access_logs" \
      -H "Authorization: ApiKey ${API_KEY}"
    ```
  </tab-item>
</tab-set>


## List all datasets

[`GET /_query/dataset`](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-esql-get-dataset) returns all registered datasets.
<tab-set>
  <tab-item title="Console">
    ```console
    GET /_query/dataset
    ```
  </tab-item>

  <tab-item title="curl">
    ```bash
    curl -X GET "${ELASTICSEARCH_URL}/_query/dataset" \
      -H "Authorization: ApiKey ${API_KEY}"
    ```
  </tab-item>
</tab-set>


## Close or open a dataset

<applies-to>Elastic Stack: Planned</applies-to> Close a dataset to stop queries from reading it, for example to control cost, then open it again after investigation. Requires `manage_dataset`, `manage`, or `all` on the dataset name. GET responses include two fields: `state` is the state of the dataset itself, `open` or `closed`, and `effective_state` tells whether queries can read it. Creating a dataset opens it, and replacing a dataset keeps its current state. Closing a closed dataset, or opening an open one, succeeds and changes nothing.
A dataset is closed for queries when it is closed, or when its data source is closed. Closing a data source does not change its datasets, so a dataset on a closed data source keeps `state: open` and shows `effective_state: closed`:
```json
{
  "datasets": [
    {
      "name": "access_logs",
      "data_source": "prod_s3_logs",
      "resource": "s3://logs/access/*.parquet",
      "state": "open",
      "effective_state": "closed"
    }
  ]
}
```

`effective_state` does not name the data source or say which of the two is closed, so it can be read with the same privileges as the dataset itself.
A closed dataset behaves as follows:
- A query that names the dataset in `FROM` fails with a `400` error that says the dataset is closed. It does not say whether the dataset or its data source was closed.
- A `FROM` wildcard skips the dataset silently, as it skips a closed index. A wildcard only reaches datasets when the `wildcards_match_datasets` query setting is on.
- A query that is already running may finish, or fail if the node that reads the dataset starts after you close it.
- You can still get, list, and replace the dataset.

To close or open datasets with a wildcard, such as `POST /_query/dataset/*/_close`, set [`action.destructive_requires_name`](/elastic/docs-builder/docs/5113/reference/elasticsearch/configuration-reference/index-management-settings#action-destructive-requires-name) to `false`. It is `true` by default, which rejects the request, as it does for closing and opening indices and for deleting datasets.
Closing and opening are refused until every node in the cluster supports them, for example during a rolling upgrade. Both actions are recorded in the [audit log](/elastic/docs-builder/docs/5113/reference/query-languages/esql/esql-data-federation-manage-datasets#audit-logging).
```console
POST /_query/dataset/access_logs/_close
```

```console
POST /_query/dataset/access_logs/_open
```


## Delete a dataset

[`DELETE /_query/dataset/{name}`](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-esql-delete-dataset) deletes a dataset by name.
Deleting a dataset doesn't check whether an [ES|QL view](https://www.elastic.co/elastic/docs-builder/docs/5113/reference/query-languages/esql/esql-views) reads from it. Views that read from a deleted dataset fail when queried.
<tab-set>
  <tab-item title="Console">
    ```console
    DELETE /_query/dataset/access_logs
    ```
  </tab-item>

  <tab-item title="curl">
    ```bash
    curl -X DELETE "${ELASTICSEARCH_URL}/_query/dataset/access_logs" \
      -H "Authorization: ApiKey ${API_KEY}"
    ```
  </tab-item>
</tab-set>


## Next steps

After creating a dataset, [query it with ES|QL](https://www.elastic.co/elastic/docs-builder/docs/5113/reference/query-languages/esql/esql-data-federation-querying). To change how the dataset selects or interprets files, return to [define a dataset](/elastic/docs-builder/docs/5113/reference/query-languages/esql/esql-data-federation-datasets#define-a-dataset).