Skip to content

API Reference parrot.tools.databasequery.sources.elastic

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.tools.databasequery.sources.elastic

View source

Elasticsearch/OpenSearch database source for DatabaseToolkit.

Implements AbstractDatabaseSource for Elasticsearch and OpenSearch using the asyncdb elastic driver. Overrides validate_query() with JSON DSL validation. Discovers schema via index mappings API.

Single source for both Elasticsearch and OpenSearch — behavior differences are handled by the asyncdb driver.

Part of FEAT-062 — DatabaseToolkit.

Alias AbstractDatabaseSource

Re-exported from parrot.tools.databasequery.base.AbstractDatabaseSource.

Alias ColumnMeta

Re-exported from parrot.tools.databasequery.base.ColumnMeta.

Class ElasticSource

Elasticsearch/OpenSearch database source.

Validates queries as JSON DSL bodies containing recognized Elasticsearch query keys. Discovers schema via index _mapping API. Works with both Elasticsearch and OpenSearch (asyncdb handles differences).

Method ElasticSource.get_default_credentials

Return default Elasticsearch credentials from environment variables.

Reads ELASTICSEARCH_HOST, ELASTICSEARCH_PORT, ELASTICSEARCH_INDEX, ELASTICSEARCH_USER, ELASTICSEARCH_PASSWORD, ELASTICSEARCH_PROTOCOL, ELASTICSEARCH_CLIENT_TYPE from navconfig via the expanded interface function.

get_default_credentials() -> dict[str, Any]

Returns: dict[str, Any] — Dict with Elasticsearch connection parameters, or empty dict if no env vars are configured.

Method ElasticSource.test_connection

Test Elasticsearch/OpenSearch connectivity using the info() call.

Overrides the base class SELECT 1 default because Elasticsearch does not support SQL. Calls info() on the underlying Elasticsearch client to verify cluster connectivity.

test_connection(credentials: dict[str, Any]) -> bool

Parameter Type Default Description
credentials dict[str, Any] Connection credentials for the Elasticsearch cluster.

Returns: bool — True if the info call succeeds, False on any exception. Never raises.

Method ElasticSource.validate_query

Validate an Elasticsearch/OpenSearch JSON DSL query body.

The query must be a JSON object containing at least one recognized Elasticsearch query key (query, aggs, size, etc.).

validate_query(query: str) -> ValidationResult

Parameter Type Default Description
query str JSON string representing an Elasticsearch query body.

Returns: ValidationResult — ValidationResult with dialect "json-dsl".

Method ElasticSource.get_metadata

Discover Elasticsearch schema via index mappings.

Returns index names as TableMeta and field properties (type, etc.) as ColumnMeta, derived from the _mapping API response.

get_metadata(credentials: dict[str, Any], tables: list[str] | None = None) -> MetadataResult

Parameter Type Default Description
credentials dict[str, Any] Connection credentials (host, port, auth).
tables list[str] | None None Optional list of index names (patterns) to inspect.

Returns: MetadataResult — MetadataResult with indices as tables and field mappings as columns.

Method ElasticSource.query

Execute an Elasticsearch JSON DSL query and return all hits.

query(credentials: dict[str, Any], sql: str, params: dict[str, Any] | None = None) -> QueryResult

Parameter Type Default Description
credentials dict[str, Any] Connection credentials. Include index for the target index name.
sql str JSON DSL query body string.
params dict[str, Any] | None None Ignored (query is embedded in the JSON body).

Returns: QueryResult — QueryResult with document hits and execution metadata.

Method ElasticSource.query_row

Execute an Elasticsearch JSON DSL query and return the first hit.

query_row(credentials: dict[str, Any], sql: str, params: dict[str, Any] | None = None) -> RowResult

Parameter Type Default Description
credentials dict[str, Any] Connection credentials.
sql str JSON DSL query body string.
params dict[str, Any] | None None Ignored.

Returns: RowResult — RowResult with the first document hit or found=False.

Alias MetadataResult

Re-exported from parrot.tools.databasequery.base.MetadataResult.

Alias QueryResult

Re-exported from parrot.tools.databasequery.base.QueryResult.

Alias RowResult

Re-exported from parrot.tools.databasequery.base.RowResult.

Alias TableMeta

Re-exported from parrot.tools.databasequery.base.TableMeta.

Alias ValidationResult

Re-exported from parrot.tools.databasequery.base.ValidationResult.

Alias register_source

Re-exported from parrot.tools.databasequery.sources.register_source.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally