Fesen HttpClient is HTTP Rest Client for Elasticsearch/OpenSearch. HttpClient provided by fesen-httpclient is HTTP-based implementation for org.opensearch.client.Client. This HttpClient supports Elasticsearch 7.x, 8.x and OpenSearch 1.x, 2.x.
<dependency>
<groupId>org.codelibs.fesen.client</groupId>
<artifactId>fesen-httpclient</artifactId>
<version>2.2.0</version>
</dependency>
// create client
final String host = "http://localhost:9200";
final Settings settings = Settings.builder().putList("http.hosts", host).put("http.compression", true).build();
final HttpClient client = new HttpClient(settings, null);
// search
client.prepareSearch("testindex").setQuery(QueryBuilders.matchAllQuery()).execute(wrap(res -> {
final long totalHits = res.getHits().getTotalHits().value;
// ...
}, e -> {
// ...
}));
For the more details, see test code in src/test/java.