Skip to content

Elasticsearch

Query Elasticsearch and OpenSearch indices as SQL tables with consistent deep pagination

Connector software
Free and open source
Service credentials
Not needed
Use with an agent

Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.

npx skills add Query-farm/vgi-skills --skill orchard

Copy this request into your coding agent to get started.

Use https://query.farm/products/orchard/connectors/elasticsearch/index.md to help me query Elasticsearch with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.

Search products and compare prices

Use your Elasticsearch endpoint and index name. This example expects name and price fields in a products index.

SELECT _id, _score, name, price
FROM elasticsearch.main.es_search('http://localhost:9200', 'products', fields => 'name:keyword,price:double')
ORDER BY price DESC
LIMIT 10;

Quick start

Choose where to run Elasticsearch, then follow the steps below.

The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.

1. Install the vgi extension

Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.

setup.sql
SET allow_extension_repositories = 'allowed';

CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
    WITH PREFIX 'https://duckdb-extensions.query.farm';

INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;

2. Attach the connector

Attach the release directly

Downloads the latest release for your platform and caches it locally.

ATTACH 'elasticsearch' AS elasticsearch (
  TYPE vgi,
  LOCATION 'github-auto://Query-farm/vgi-elasticsearch'
);

3. Run a query

query.sql
SELECT _id, _score, name, price
FROM elasticsearch.main.es_search('http://localhost:9200', 'products', fields => 'name:keyword,price:double')
ORDER BY price DESC
LIMIT 10;
More example queries β†’
Technical details
Verified connector release
v0.5.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
Pin a version for production

When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.

Attach the release directly

Uses the verified release each time you attach the connector.

ATTACH 'elasticsearch' AS elasticsearch (
  TYPE vgi,
  LOCATION 'github-auto://Query-farm/[email protected]'
);

Overview

Query Elasticsearch/OpenSearch indices as SQL tables (PIT + search_after deep pagination via externalized scan state)

Catalog

Everything elasticsearch exposes once attached β€” read straight from the worker's released build.

elasticsearch 1 schema
main 1 view Β· 1 function

Elasticsearch/OpenSearch search functions.

Schema examples (5)
Examples (5)

Bind the column schema for the products index from an explicit fields spec: the _id/_score meta columns plus one typed column per declared source field.

DESCRIBE SELECT _id, _score, name, price
FROM elasticsearch.main.es_search('http://localhost:9200', 'products', fields => 'name:keyword,price:double');

Bind the schema for a projected, filtered, sorted read of the products index β€” name/price project down via _source filtering and price > 100 pushes into the query DSL.

DESCRIBE SELECT name, price
FROM elasticsearch.main.es_search('http://localhost:9200', 'products', fields => 'name:keyword,price:double')
WHERE price > 100
ORDER BY price DESC;

Bind the schema for an error-log scan over the logs-* index pattern on an Elasticsearch cluster, using API-key auth, the Elasticsearch PIT dialect, and a raw query-DSL escape hatch.

DESCRIBE SELECT level
FROM elasticsearch.main.es_search('https://es.example.com', 'logs-*', fields => 'level:keyword', api_key => 'BASE64APIKEY', flavor => 'elasticsearch', query => '{"term":{"level":"error"}}');

Bind the result schema (name, shipped_orders, units, revenue) of a join between two indices, which the Elasticsearch query DSL cannot do. Run without DESCRIBE, it returns one row per product that has shipped orders: its count of shipped orders, units shipped and revenue (sum of qty * price), from an `orders` index joined to a `products` index on product_id, highest revenue first. The `status = 'shipped'` filter is pushed into the orders search as a term query. The explicit `fields` specs let the schema resolve without a live cluster.

DESCRIBE SELECT p.name, count(*) AS shipped_orders, sum(o.qty) AS units, sum(o.qty * p.price) AS revenue
FROM elasticsearch.main.es_search('http://localhost:9200', 'orders', fields => 'product_id:keyword,qty:long,status:keyword') AS o
JOIN elasticsearch.main.es_search('http://localhost:9200', 'products', fields => 'product_id:keyword,name:keyword,price:double') AS p ON o.product_id = p.product_id
WHERE o.status = 'shipped'
GROUP BY p.name
ORDER BY revenue DESC, p.name;
1 more example

Bind the result schema (order_id, product_id, qty) of a cross-index data-quality check. Run without DESCRIBE, it lists the orders whose product_id matches no document in the `products` index, using an anti-join between two es_search scans. The explicit `fields` specs let the schema resolve without a live cluster.

DESCRIBE SELECT o._id AS order_id, o.product_id, o.qty
FROM elasticsearch.main.es_search('http://localhost:9200', 'orders', fields => 'product_id:keyword,qty:long') AS o ANTI
JOIN elasticsearch.main.es_search('http://localhost:9200', 'products', fields => 'product_id:keyword') AS p ON o.product_id = p.product_id
ORDER BY o._id;
Views
es_type_mapping 2 examples4 cols

Reference: how each Elasticsearch/OpenSearch field type maps to a DuckDB column type in es_search (one row per ES type). Browsable with no cluster.

Columns
es_type VARCHAR
The Elasticsearch/OpenSearch field type (as it appears in the index mapping or an es_search `fields` spec entry).
duckdb_type VARCHAR
The DuckDB column type es_search emits for this ES type.
category VARCHAR
Coarse grouping of the ES type: string, integer, float, boolean, temporal, or json.
notes VARCHAR
A short human note on how the value is surfaced.
Examples (2)

List the ES types that es_search surfaces as raw JSON text (object/nested/geo).

SELECT es_type, duckdb_type
FROM elasticsearch.main.es_type_mapping
WHERE category = 'json'
ORDER BY es_type;

How many distinct DuckDB types does es_search map ES field types onto, and which ES types feed each?

SELECT duckdb_type, count(*) AS es_types,
  string_agg(es_type, ', ' ORDER BY es_type) AS from_es
FROM elasticsearch.main.es_type_mapping
GROUP BY duckdb_type
ORDER BY es_types DESC;
Link
Table functions

Try these queries

Bind the column schema for the products index from an explicit fields spec: the _id/_score meta columns plus one typed column per declared source field.

DESCRIBE SELECT _id, _score, name, price
FROM elasticsearch.main.es_search('http://localhost:9200', 'products', fields => 'name:keyword,price:double');

Uses es_search

Bind the schema for a projected, filtered, sorted read of the products index β€” name/price project down via _source filtering and price > 100 pushes into the query DSL.

DESCRIBE SELECT name, price
FROM elasticsearch.main.es_search('http://localhost:9200', 'products', fields => 'name:keyword,price:double')
WHERE price > 100
ORDER BY price DESC;

Uses es_search

Bind the schema for an error-log scan over the logs-* index pattern on an Elasticsearch cluster, using API-key auth, the Elasticsearch PIT dialect, and a raw query-DSL escape hatch.

DESCRIBE SELECT level
FROM elasticsearch.main.es_search('https://es.example.com', 'logs-*', fields => 'level:keyword', api_key => 'BASE64APIKEY', flavor => 'elasticsearch', query => '{"term":{"level":"error"}}');

Uses es_search

Bind the result schema (name, shipped_orders, units, revenue) of a join between two indices, which the Elasticsearch query DSL cannot do. Run without DESCRIBE, it returns one row per product that has shipped orders: its count of shipped orders, units shipped and revenue (sum of qty * price), from an `orders` index joined to a `products` index on product_id, highest revenue first. The `status = 'shipped'` filter is pushed into the orders search as a term query. The explicit `fields` specs let the schema resolve without a live cluster.

DESCRIBE SELECT p.name, count(*) AS shipped_orders, sum(o.qty) AS units, sum(o.qty * p.price) AS revenue
FROM elasticsearch.main.es_search('http://localhost:9200', 'orders', fields => 'product_id:keyword,qty:long,status:keyword') AS o
JOIN elasticsearch.main.es_search('http://localhost:9200', 'products', fields => 'product_id:keyword,name:keyword,price:double') AS p ON o.product_id = p.product_id
WHERE o.status = 'shipped'
GROUP BY p.name
ORDER BY revenue DESC, p.name;

Uses es_search

Bind the result schema (order_id, product_id, qty) of a cross-index data-quality check. Run without DESCRIBE, it lists the orders whose product_id matches no document in the `products` index, using an anti-join between two es_search scans. The explicit `fields` specs let the schema resolve without a live cluster.

DESCRIBE SELECT o._id AS order_id, o.product_id, o.qty
FROM elasticsearch.main.es_search('http://localhost:9200', 'orders', fields => 'product_id:keyword,qty:long') AS o ANTI
JOIN elasticsearch.main.es_search('http://localhost:9200', 'products', fields => 'product_id:keyword') AS p ON o.product_id = p.product_id
ORDER BY o._id;

Uses es_search

List the ES types that es_search surfaces as raw JSON text (object/nested/geo).

SELECT es_type, duckdb_type
FROM elasticsearch.main.es_type_mapping
WHERE category = 'json'
ORDER BY es_type

Uses es_type_mapping

3 more examples in the Catalog, each listed under the table or function it uses.

Elasticsearch is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.