Blog

How to query Amazon S3 from Elasticsearch with ES|QL, no ingest required

Run FROM against the Parquet, NDJSON or CSV files already in your bucket and correlate the results with your indexed data in the same request, with a public dataset to try if you have none handy.

Get hands-on with Elasticsearch: Dive into our sample notebooks in the Elasticsearch Labs repo, start a free cloud trial, or try Elastic on your local machine now.

You can query Parquet, NDJSON, and CSV files in Amazon S3 from Elasticsearch with the same FROM clause you use for an index. Two PUT requests register the bucket, and Elasticsearch infers the schema at query time. Nothing is copied into the cluster. Correlate that S3 data against your indexed alerts in one Elasticsearch Query Language (ES|QL) request, filter it with MATCH, and wrap it in a view or point Elastic Agent Builder at it.

In this post, we walk you through the process. For the announcement and the architecture behind the query performance, read ES|QL Data Federation: Elasticsearch now queries data where it lives.

ES|QL Data Federation is in technical preview in Elastic Cloud Serverless, and coming to Elasticsearch 9.6 in December on Elastic Cloud Hosted (ECH) and Elastic Self-Managed. It needs an Enterprise subscription, and it’s off by default, so before you start, check the prerequisites below.

How ES|QL Data Federation queries S3

ES|QL Data Federation uses a two-step configuration model: a data_source (where to connect) and a dataset (what to query). Both are managed via the _query/ API namespace.

Step 1: Register an S3 data source in Elasticsearch

A data_source holds credentials and endpoint configuration. Secrets are encrypted at rest in cluster state and decrypted only at query time in memory; they're never returned on GET.

To create a data_source, run this API call in Dev Tools (with your own credentials): 

PUT _query/data_source/my_s3
{
  "type": "s3",
  "description": "Demo object storage",
  "settings": {
    "access_key": "AKIA...",
    "secret_key": "wJal..."
  }
}

For public buckets, omit long-lived keys and use "auth": "anonymous":

PUT _query/data_source/public_s3
{
  "type": "s3",
  "settings": {
    "auth": "anonymous"
  }
}

For the best security posture or if your organization’s cloud security policy requires it, prefer keyless / workload-identity federation so Elasticsearch requests a short-lived token per query and so no long-lived cloud key leaves your account. See the AWS auth setup guide in the docs for the trust-relationship pattern.

Step 2: Define a dataset for your S3 files

A dataset references a data_source and specifies the resource path. At minimum, you point it at your files:

PUT _query/dataset/cloudtrail_parquet

{
  "data_source": "my_s3",
  "resource": "s3://my-bucket/cloudtrail/**/*.parquet"
}

The glob pattern **/*.parquet matches all Parquet files under that prefix, regardless of how many subdirectories deep they are. That's enough to start querying.

Map a timestamp field for Kibana’s time picker

Kibana looks for a column named @timestamp to drive the time picker and the Discover histogram, along with dashboard time ranges. CloudTrail stores its event time in eventTime, so rename it with a mappings block:

PUT _query/dataset/cloudtrail_parquet
{
  "data_source": "my_s3",
  "resource": "s3://my-bucket/cloudtrail/**/*.parquet",
  "mappings": {
    "properties": {
      "@timestamp": { "type": "date", "path": "eventTime" }
    }
  }
}

path names the column in your files. The rename replaces the name, so query @timestamp (not eventTime) from this point on.  Every other column is still inferred automatically. If your timestamps are strings in a non–International Organization for Standardization (non-ISO) format, add a format (for example, "format": "dd/MMM/yyyy:HH:mm:ss Z") for web access logs. In Kibana, the dataset wizard's Mapping step does the same thing.

A timestamp also speeds up queries. A time-range filter on @timestamp is pushed down to Parquet, so row groups outside the window are skipped instead of read.

Detect Hive partitions in your S3 paths

If your S3 layout uses key=value directory names (for example, s3://my-bucket/cloudtrail/year=2026/month=07/.parquet), you can tell Elasticsearch to treat those path segments as queryable fields:

PUT _query/dataset/cloudtrail_parquet
{
  "data_source": "my_s3",
  "resource": "s3://my-bucket/cloudtrail/**/*.parquet",
  "settings": { "partition_detection": "hive" },
  "mappings": {
    "properties": {
      "@timestamp": { "type": "date", "path": "eventTime" }
    }
  }
}

With Hive partition detection enabled, year and month appear as fields that you can filter on. Elasticsearch only scans files in directories that match your predicates, skipping everything else:

FROM cloudtrail_parquet
| WHERE year == "2026"
| STATS event_count = COUNT(*) BY eventName
| SORT event_count DESC

Without partition pruning, that query would read every file across all years and months. Most data lake exports (such as CloudTrail, AWS Security Lake, and Athena outputs) already use this layout, so enabling it is usually the right default for partitioned data. Step 3: Query S3 files with FROM

Once registered, a dataset is queryable exactly like an Elasticsearch index. Try this in Discover:

FROM cloudtrail_parquet | LIMIT 5

There's no new syntax to learn, and there are no special commands. You work with the same FROM clause that you use for indices, aliases, and views, and the same processing commands (WHERE, STATS, EVAL, SORT) apply. Results land in the same Kibana Discover and dashboards that you already use.

Supported file formats, compression, and cloud storage

Available in Elasticsearch 9.6 on ECH and Elastic Self-Managed:

Capability

Supported at launch

Coming soon

Cloud storage

Amazon S3

Google Cloud Storage, Azure Blob Storage

File formats

Parquet, NDJSON, CSV/TSV

optimized row columnar (ORC)

Compression

gzip, zstd, snappy, uncompressed

Additional compression schemes

Schema inference

Automatic (Parquet, NDJSON, CSV); optional mapping to rename, retype, or name a time field

n/a

Path patterns

Glob (**/*.parquet), Hive partitioning

n/a

Schema inference detects column types automatically, so no mapping is required. Add one to name a time field or to pin a column's type. Databases and data warehouses are on the roadmap, using the same FROM syntax.

Query Parquet, NDJSON, and CSV files in S3

Use the same FROM pattern for each format. Register one data_source and then one dataset per layout:

PUT _query/dataset/events_parquet
{
  "data_source": "my_s3",
  "resource": "s3://my-bucket/events/**/*.parquet"
}

PUT _query/dataset/events_ndjson
{
  "data_source": "my_s3",
  "resource": "s3://my-bucket/events/**/*.ndjson"
}

PUT _query/dataset/events_csv
{
  "data_source": "my_s3",
  "resource": "s3://my-bucket/events/**/*.csv.gz"
}

FROM events_parquet
| STATS rows = COUNT(*) BY eventName
| SORT rows DESC
| LIMIT 10

Compressed files (gzip, zstd, snappy) are supported where documented for the format. The .csv.gz path, shown above, is a typical pattern.

Combine S3 data and Elasticsearch index data in one ES|QL query

External data doesn't exist in a vacuum. Subqueries in FROM let you combine external and indexed data in one ES|QL request. Query your indexed alerts and your archived CloudTrail data in the same statement. The following field names assume CloudTrail-style Parquet (eventName, sourceIPAddress) on the S3 side and Elastic Common Schema–style (ECS-style) fields on indexed firewall logs. Adjust to your schemas.

Technique

What it does

Use when

Subquery in FROM

Runs separate queries and unions the results.

You need different filters or aggregations per source.

Multi-source FROM

One scan list across indices and datasets.

Sources share a schema, and you want one pass.

LOOKUP JOIN

Enriches rows with fields from a lookup index.

You need context added to external data.

IN subquery

Filters one source by values pulled from another.

You want a value set, not a join.

Views

Names a reusable query over datasets.

Teams need a clean interface over raw S3 paths.

FROM (
    FROM fw-logs-*
    | WHERE event.action == "deny"
    | EVAL ip = TO_STRING(source.ip)
    | STATS denied_count = COUNT(*) BY ip
  ), (
    FROM cloudtrail_parquet
    | WHERE eventName == "ConsoleLogin"
    | STATS login_count = COUNT(*) BY ip = sourceIPAddress
  )
| STATS denied_count = SUM(denied_count), login_count = SUM(login_count) BY ip
| WHERE denied_count > 5 AND login_count > 0
| SORT denied_count DESC
| LIMIT 20

Two data planes (indexed firewall logs and archived CloudTrail in S3) are queried together. There's no extract, transform, load (ETL) tooling or intermediate pipeline, nor is there an export-and-rejoin workflow. You stay in Kibana and use one language, and you correlate across live and historical data in the same session.

You can also query multiple sources in a single FROM (comma-separated indices and/or datasets); for example, FROM fw-logs-*, cloudtrail_parquet | …. That’s a different construct from subqueries: one scan list, not nested FROM (…), (…) branches. 

You can also combine with LOOKUP JOIN for enrichment. Enrich external data with context from a lookup index. For example, enrich CloudTrail events from S3 with an internal asset registry:

FROM cloudtrail_parquet
| WHERE eventName == "ConsoleLogin"
| EVAL join_ip = sourceIPAddress
| LOOKUP JOIN asset_registry ON join_ip
| KEEP @timestamp, sourceIPAddress, asset_owner, asset_criticality, eventName
| SORT @timestamp DESC

The CloudTrail data lives in S3; the asset_registry is a lookup index in Elasticsearch. There's no export or pipeline, just a join across storage tiers in one query.

Plus, you can filter with IN-subquery. Pull a set of values from an external dataset into a filter on indexed data (or the reverse):

FROM alerts-*
| WHERE source.ip IN (
    FROM cloudtrail_parquet
    | WHERE eventName == "ConsoleLogin"
    | EVAL ip = TO_IP(sourceIPAddress) 
    | KEEP ip
  )
| STATS alert_count = COUNT(*) BY source.ip
| SORT alert_count DESC
| LIMIT 20

You can also define ES|QL views that reference external datasets, giving teams a named, reusable abstraction over raw S3 paths. A view can pre-apply filters, rename columns, or combine multiple datasets so downstream users query a clean interface without needing to know the underlying storage layout. Views are created via the _query/view API:

PUT _query/view/cloudtrail_console_logins
{
  "query": """
    FROM cloudtrail_parquet
    | WHERE eventName == "ConsoleLogin"
    | KEEP @timestamp, sourceIPAddress, awsRegion, userIdentity_arn
  """
}

FROM cloudtrail_console_logins
| STATS logins = COUNT(*) BY awsRegion
| SORT logins DESC

Explore an unfamiliar S3 dataset with schema inference

Schema inference means that you can point at unfamiliar data and start querying immediately, with no mapping or pipeline; for example, profiling a feed of daily CSV exports:

PUT _query/dataset/partner_feed_csv
{
  "data_source": "my_s3",
  "resource": "s3://data-feeds/partner/2026/**/*.csv"
}

FROM partner_feed_csv
| STATS total = COUNT(*), distinct_users = COUNT_DISTINCT(user_id) BY category
| SORT total DESC

Column types are inferred at query time. Once you know that the data is worth keeping around, you can decide whether to bring it into Elasticsearch for recurring use.

Run full-text search on S3 data with MATCH

At technical preview, MATCH and MATCH_PHRASE work on external datasets and return relevance scores. For now, wrap the field in TO_TEXT() so string columns are analyzed as text. Without it, a query may still return HTTP 200, but matching is wrong for real text, especially multi-word phrases, because Parquet, CSV, and NDJSON string columns aren’t treated as analyzable text until you cast them.

FROM partner_feed_csv METADATA _score
| WHERE MATCH(TO_TEXT(description), "failed invoice")
| KEEP user_id, category, description, _score
| SORT _score DESC
| LIMIT 50

Vector search works, too, in technical preview. The DENSE_VECTOR command generates embeddings at query time from a text column, and you can compare them with k-nearest neighbor (kNN) or vector similarity functions, such as V_COSINE. There's no vector index on external data, so each comparison runs against every row. Filter first to keep the row count down.

FROM partner_feed_csv
| WHERE category == "billing"
| DENSE_VECTOR description
| EVAL similarity = V_COSINE(description_dense_vector, TEXT_EMBEDDING("customer can't pay an invoice", "my-embedding-endpoint"))
| SORT similarity DESC
| KEEP user_id, description, similarity
| LIMIT 10

For high-volume semantic retrieval, ingest the data so it can use a vector index.

Query S3 datasets from Agent Builder

Every example that we’ve covered so far runs from Discover or Dev Tools, but a registered dataset works anywhere that ES|QL runs, because it behaves like an index. That includes Agent Builder; the same CloudTrail dataset you queried above becomes context an agent can use, without ingesting the archive first.

  1. Register a data_source and dataset, as above; for example, cloudtrail_parquet or redset_queries.

  2. In Agent Builder, ask in natural language. You don't need to name the dataset or say "ES|QL." (ES|QL is the default.) Mentioning "CloudTrail logs" is enough for the agent to find a registered cloudtrail_parquet dataset.

  3. Confirm that the agent generates a query against the dataset and returns rows.

Example prompt:

Summarize ConsoleLogin events in my CloudTrail logs from the last 7 days by region.

What the agent might run (illustrative):

FROM cloudtrail_parquet
| WHERE eventName == "ConsoleLogin" AND @timestamp > NOW() - 7 days
| STATS logins = COUNT(*) BY awsRegion
| SORT logins DESC

Getting started: Query your first S3 file

  • Start with ECH: ES|QL Data Federation is available now as a technical preview in Elastic Cloud Serverless, and coming to Elasticsearch 9.6 in December. Start a free Elastic Cloud trial, and create a 9.6 deployment. Or upgrade your existing ECH or Elastic Self-Managed cluster to 9.6.

  • Register a data_source: Point at your S3 bucket with credentials, or use "auth": "anonymous" for public buckets (see ES|QL Data Federation documentation).

  • Create a dataset: Define the resource path and partition settings.

  • Query from Kibana: Open Discover or Dev Tools, and run FROM your_dataset | LIMIT 5. If you see rows, you're in.

  • Optional: Try datasets in subqueries or views, use with LOOKUP JOIN, and in Agent Builder, as above.

Try it on a public S3 dataset, no credentials required

If you don’t have a bucket handy, try Amazon's public Redset sample: 1% of real Redshift Serverless query workloads in Parquet, no credentials needed:

PUT _query/data_source/public_redset
{
  "type": "s3",
  "settings": { "auth": "anonymous" }
}
PUT _query/dataset/redset_queries
{
  "data_source": "public_redset",
  "resource": "s3://redshift-downloads/redset/serverless/sample_0.01.parquet"
}

FROM redset_queries
| STATS query_count = COUNT(*), avg_exec_ms = AVG(execution_duration_ms), total_scanned_mb = SUM(mbytes_scanned) BY query_type
| SORT query_count DESC
| LIMIT 10

Learn more about ES|QL Data Federation

If you’re ready to try it, start a free Elastic Cloud trial, create a new project, and run your first FROM against S3 today. If you don’t have a bucket handy, the public Redset example, mentioned above, works out of the box.

Statements regarding future features, timelines, and commercial availability are forward-looking and subject to change. ES|QL Data Federation is in technical preview: APIs, syntax, performance characteristics, and subscription packaging may change before general availability. Not recommended for production-critical workloads without evaluation of risk and Elastic guidance.

Frequently Asked Questions

Can I combine live Elasticsearch index data with S3 data in a single query?

Yes. ES|QL subqueries in FROM let you query indexed data and external S3 data in the same statement, and LOOKUP JOIN lets you enrich external data with a lookup index in Elasticsearch. Both run in one ES|QL request, with no export-and-rejoin step.

Do I need to change my Elasticsearch security or role-based access control (RBAC) setup to query external S3 data?

No. Data source credentials are encrypted at rest in cluster state and decrypted only in memory at query time; they're never returned on GET. Queries against external datasets run through the same Kibana Discover, Dashboards, and RBAC model that you already use for indexed data.

Do I need to define a schema or mapping before querying files in S3?

No. Schema inference detects column types at query time. Add an optional `mappings` block to rename a column to `@timestamp` for Kibana's time picker, pin types across files, or parse custom date formats.

How do I query files spread across many paths or partitions?

Datasets support glob patterns (for example, `**/*.parquet`) and Hive-style partition detection, so a single dataset can cover an entire partitioned layout, as long as they’re the same format.

Can Agent Builder use external datasets?

Yes, once datasets are registered, just mention them like any other data in your environment.

How helpful was this content?

Related Content

Kibana custom panels: Any dashboard visual, generated from one prompt

Kibana custom panels: Any dashboard visual, generated from one prompt

Teresa Alvarez Soler
ES|QL Data Federation: Elasticsearch now queries data where it lives

ES|QL Data Federation: Elasticsearch now queries data where it lives

Tyler Perkins
Elasticsearch 9.6: Query Amazon S3 data in place, multiuser chat, and PDFs to Markdown

Elasticsearch 9.6: Query Amazon S3 data in place, multiuser chat, and PDFs to Markdown

Gregory Chase
The fastest work is the work you never do: 100x faster sorted queries in Elasticsearch

The fastest work is the work you never do: 100x faster sorted queries in Elasticsearch

Attila Sahi
The best LLM writes correct Elasticsearch ES|QL 59% of the time. Here's what breaks the other 41%.

The best LLM writes correct Elasticsearch ES|QL 59% of the time. Here's what breaks the other 41%.

Jeffrey Rengifo

Ready to build state of the art search experiences?

Sufficiently advanced search isn’t achieved with the efforts of one. Elasticsearch is powered by data scientists, ML ops, engineers, and many more who are just as passionate about search as you are. Let’s connect and work together to build the magical search experience that will get you the results you want.