Elasticsearch
Query Elasticsearch and OpenSearch indices as SQL tables with consistent deep pagination
- Connector software
- Free and open source
- Service credentials
- Not needed
- Query Farm hosting
- Available Β· $10/month organization minimum
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.
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;
INSTALL vgi FROM community;
LOAD vgi;
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'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'elasticsearch' AS elasticsearch (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-elasticsearch:0.5.0'
);
3. Run a query
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;
Run the connector on a server you manage. You operate the service and choose who can connect.
1. Deploy the connector on your server
Follow the connectorβs deployment instructions. Use its supported HTTP transport, or launch it remotely over SSH. The connection guide explains both options.
2. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
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;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach the connector
For an HTTP deployment, replace the example URL with your endpoint. Add the authentication options your deployment requires. For SSH, use the SSH connection instructions.
ATTACH 'elasticsearch' AS elasticsearch
(TYPE vgi, LOCATION 'https://your-connector.example.com');
4. Run a query
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;
Query Farm operates Elasticsearch for your team. Hosting has a $10 monthly minimum per organization; usage counts toward it. From $2.97 per instance-month ($10 monthly minimum).
1. Create your hosted connector
Open the console, choose your organization and deployment size, and add any service credentials there.
2. Install the vgi extension
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;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach your deployment
Copy the ATTACH statement from your deployment in the console and run it in DuckDB or Haybarn. Use elasticsearch as the catalog alias for the query below.
4. Run a query
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;
Technical details
- Verified connector release
- v0.5.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
- Verified on
- December 1, 2026
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]'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'elasticsearch' AS elasticsearch (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-elasticsearch:0.5.0'
);
Overview
Query Elasticsearch/OpenSearch indices as SQL tables (PIT + search_after deep pagination via externalized scan state)
![]()
Query Elasticsearch and OpenSearch indices as live SQL tables over Apache Arrow β full-text search, the query DSL, and consistent deep pagination, straight from DuckDB SQL with no application code.
This VGI worker turns any Elasticsearch or OpenSearch cluster into queryable tables inside DuckDB. It is built for data engineers, analysts, and anyone who needs to read, filter, join, and export search-engine data without standing up a separate ETL pipeline or learning a client library. Point it at a cluster endpoint and an index (or an index pattern such as logs-*) and select the fields you want; the worker handles authentication, mapping introspection, pagination, and the translation of SQL filters into Elasticsearch query DSL for you. It works with both the commercial Elasticsearch distribution from Elastic and the Apache-2.0 licensed OpenSearch fork.
Under the hood the worker speaks the native Elasticsearch/OpenSearch REST API and JSON query DSL directly over HTTP. Large result sets are streamed using a Point-In-Time (PIT) snapshot combined with a search_after cursor, and that cursor is carried as externalized scan state β so a scan resumes cleanly across batch boundaries with no duplicated and no dropped documents, even across millions of hits. The flavor option selects the correct PIT dialect for OpenSearch versus Elasticsearch. See the Elasticsearch documentation and the OpenSearch documentation for cluster-side details.
Reads support projection pushdown (only the requested fields are fetched via _source filtering), predicate pushdown (term, terms, range, and exists filters are compiled into the query DSL), a raw query-DSL escape hatch for anything more advanced, explicit sort, and basic-auth or API-key credentials. Every row carries the document _id and relevance _score alongside one typed column per source field. Typical use cases include exploring and aggregating log or product indices, joining search hits against local DuckDB tables or Parquet files, and exporting filtered subsets β for example projecting name and price from a products index, keeping only rows where price exceeds a threshold, and ordering by price. See the es_search function's examples for ready-to-run queries, and browse the es_type_mapping view to see how each Elasticsearch field type becomes a DuckDB column type.
Catalog
Everything elasticsearch exposes once attached β read straight from the worker's
released build.
main 1 view Β· 1 function
Elasticsearch/OpenSearch search functions.
Schema 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;
es_type_mapping
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.
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;
es_search (endpoint VARCHAR, index VARCHAR, fields := VARCHAR, query := VARCHAR, sort := VARCHAR, flavor := VARCHAR, keep_alive := VARCHAR, page_size := BIGINT, username := VARCHAR, password := VARCHAR, api_key := VARCHAR, insecure_tls := BOOLEAN)
Query an Elasticsearch/OpenSearch index as a SQL table: consistent deep pagination via PIT + search_after (cursor in externalized scan state), with _source projection pushdown and query-DSL predicate pushdown
Bind the column schema for the products index from an explicit fields spec. The _id/_score meta columns are always present; each declared source field becomes a typed column (here name is `VARCHAR`, price is `DOUBLE`).
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. At runtime name/price project down via _source filtering and price > 100 pushes into the Elasticsearch query DSL; the explicit fields spec lets the column shape resolve without a live cluster.
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. The explicit fields spec resolves the column shape without contacting the cluster.
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"}}');
4 more examples
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;
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;
DESCRIBE SELECT *
FROM elasticsearch.main.es_search('http://localhost:9200', 'products', fields => 'name:keyword,price:double');
DESCRIBE SELECT _id, level
FROM elasticsearch.main.es_search('http://localhost:9200', 'logs', fields => 'level:keyword');
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.
Related workers
NATS
Databases & messaging
NATS server monitoring and read-only JetStream streams, consumers, messages, KV and object stores
OData
Databases & messaging
Read OData v2/v4 REST services from SQL, with $filter pushdown, automatic paging and metadata discovery
Google Pub/Sub
Databases & messaging
Topics, subscriptions, schemas, IAM, backlog metrics and opt-in message replay from Google Cloud Pub/Sub