Exploration of Efficient Solutions for Creating Indices and Ingesting Data in OpenSearch container for Tests
3 min readMay 5, 2024
Recently, I wanted to add integration tests for a project that used OpenSearch as the search engine. To ensure isolation and have a clean way of creating indexes and ingesting initial data, I explored better solutions than simply making REST requests in the @BeforeAll
methods, which can be error-prone and lead to inconsistencies. So, I started a short exploration to see what possible solutions were available.
After conducting some research, I identified several approaches that can be categorized as follows:
- Programmatic Approaches:
OpenSearch REST API: Utilizing the OpenSearch REST API involves sending HTTP requests directly to manage indices and ingest data. While this method is language-agnostic, it can become verbose and might not suit all testing needs due to its low-level nature.
OpenSearch Java High-Level REST Client: Ideal for Java-based projects, this client provides a more streamlined and idiomatic approach to interacting with OpenSearch. It simplifies tasks like creating indices and ingesting data, making it a preferred choice for Java developers.
OpenSearch Low-Level REST Client: This is a more direct and granular Java API that offers detailed control over OpenSearch interactions. It requires more setup and boilerplate code…