class OpenSearchContainer(image: str = 'opensearchproject/opensearch:2.4.0', port: int = 9200, security_enabled: bool = False, **kwargs)ΒΆ

The following example demonstrates how to create a new index in an OpenSearch container and add a document to it. It also shows how to search within the created index. The refresh step in between makes sure that the newly created document is available for search.

The method get_client can be used to create a OpenSearch Python Client. The method get_config can be used to retrieve the host, port, username, and password of the container.


>>> from testcontainers.opensearch import OpenSearchContainer

>>> with OpenSearchContainer() as opensearch:
...   client = opensearch.get_client()
...   creation_result = client.index(index="test", body={"test": "test"})
...   refresh_result = client.indices.refresh(index="test")
...   search_result ="test", body={"query": {"match_all": {}}})