Skip to content

Commit

Permalink
Update IndicesResource.java
Browse files Browse the repository at this point in the history
add async client
  • Loading branch information
sboeckelmann authored Jul 16, 2024
1 parent 9dfeeaf commit e2d18d2
Showing 1 changed file with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,33 @@
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

import org.opensearch.client.opensearch.OpenSearchAsyncClient;
import org.opensearch.client.opensearch.OpenSearchClient;

@Path("/indices")
import io.smallrye.mutiny.Uni;

@Path("/")
public class IndicesResource {

@Inject
OpenSearchClient client;

@Inject
OpenSearchAsyncClient asyncClient;

@GET
@Path("/indices")
@Produces(MediaType.TEXT_PLAIN)
public String hello() throws IOException {
public String indices() throws IOException {
return client.cat().indices().valueBody().stream().map(e -> e.index()).collect(Collectors.joining("\n"));
}

@GET
@Path("/indices-async")
@Produces(MediaType.TEXT_PLAIN)
public Uni<String> indicesAsync() throws IOException {
return Uni.createFrom().completionStage(asyncClient.cat().indices())
.chain(r -> Uni.createFrom()
.item(r.valueBody().stream().map(t -> t.index()).collect(Collectors.joining("\n"))));
}
}

0 comments on commit e2d18d2

Please sign in to comment.