Skip to content

Data store

OpenSearch data store with capability composition.

Authors

Kadek Denaya (kadek.d.r.diana@gdplabs.id)

References

NONE

OpenSearchDataStore(index_name, client=None, url=None, cloud_id=None, api_key=None, username=None, password=None, request_timeout=DEFAULT_REQUEST_TIMEOUT)

Bases: BaseDataStore

OpenSearch data store with multiple capability support.

This is the explicit public API for OpenSearch. Users know they're using OpenSearch, not a generic "elastic-like" datastore.

Attributes:

Name Type Description
engine str

Always "opensearch" for explicit identification. This attribute ensures users know they're using OpenSearch, not a generic "elastic-like" datastore.

index_name str

The name of the OpenSearch index.

client AsyncOpenSearch

AsyncOpenSearch client.

Initialize the OpenSearch data store.

Parameters:

Name Type Description Default
index_name str

The name of the OpenSearch index to use for operations. This index name will be used for all queries and operations.

required
client AsyncOpenSearch | None

Pre-configured OpenSearch client instance. If provided, it will be used instead of creating a new client from url/cloud_id. Must be an instance of AsyncOpenSearch. Defaults to None.

None
url str | None

The URL of the OpenSearch server. For example, "http://localhost:9200". Either url or cloud_id must be provided if client is None. Defaults to None.

None
cloud_id str | None

The cloud ID of the OpenSearch cluster. Used for OpenSearch Service connections. Either url or cloud_id must be provided if client is None. Defaults to None.

None
api_key str | None

The API key for authentication. If provided, will be used for authentication. Mutually exclusive with username/password. Defaults to None.

None
username str | None

The username for basic authentication. Must be provided together with password. Mutually exclusive with api_key. Defaults to None.

None
password str | None

The password for basic authentication. Must be provided together with username. Mutually exclusive with api_key. Defaults to None.

None
request_timeout int

The request timeout in seconds. Defaults to DEFAULT_REQUEST_TIMEOUT.

DEFAULT_REQUEST_TIMEOUT

Raises:

Type Description
ValueError

If neither url nor cloud_id is provided when client is None.

TypeError

If client is provided but is not an instance of AsyncOpenSearch.

fulltext property

Access fulltext capability if supported.

This method uses the logic of its parent class to return the fulltext capability handler. This method overrides the parent class to return the OpenSearchFulltextCapability handler for better type hinting.

Returns:

Name Type Description
OpenSearchFulltextCapability OpenSearchFulltextCapability

Fulltext capability handler.

Raises:

Type Description
NotSupportedException

If fulltext capability is not supported.

supported_capabilities property

Return list of currently supported capabilities.

Returns:

Type Description
list[str]

list[str]: List of capability names that are supported. Currently returns [CapabilityType.FULLTEXT, CapabilityType.VECTOR]. Note: Vector capability is not yet implemented.

vector property

Access vector capability if supported.

Raises:

Type Description
NotImplementedError

Vector capability not yet implemented.

translate_query_filter(query_filter) classmethod

Translate QueryFilter or FilterClause to OpenSearch native filter syntax.

This method delegates to the OpenSearchQueryTranslator and returns the result as a dictionary.

Parameters:

Name Type Description Default
query_filter FilterClause | QueryFilter | None

The filter to translate. Can be a single FilterClause, a QueryFilter with multiple clauses and logical conditions, or None for empty filters. FilterClause objects are automatically converted to QueryFilter.

required

Returns:

Type Description
dict[str, Any] | None

dict[str, Any] | None: The translated filter as an OpenSearch DSL dictionary. Returns None for empty filters or when query_filter is None. The dictionary format matches OpenSearch Query DSL syntax.

with_fulltext(index_name=None, query_field='text')

Configure fulltext capability and return datastore instance.

This method uses the logic of its parent class to configure the fulltext capability. This method overrides the parent class for better type hinting.

Parameters:

Name Type Description Default
index_name str | None

The name of the OpenSearch index to use for fulltext operations. If None, uses the default index_name from the datastore instance. Defaults to None.

None
query_field str

The field name to use for text content in queries. This field will be used for BM25 and other text search operations. Defaults to "text".

'text'

Returns:

Name Type Description
OpenSearchDataStore OpenSearchDataStore

Self for method chaining.

with_vector(*args, **kwargs)

Configure vector capability and return datastore instance.

Parameters:

Name Type Description Default
*args Any

Placeholder arguments.

()
**kwargs Any

Placeholder keyword arguments.

{}

Returns:

Name Type Description
Self OpenSearchDataStore

Self for method chaining.

Raises:

Type Description
NotImplementedError

Vector capability not yet implemented.