The official Java client for Elasticsearch.
This project is still a work in progress
This high-level client provides strongly typed requests and responses for all Elasticsearch APIs. It uses the Java low-level client for all transport-level concerns (http connection establishment and pooling, retries, etc).
The docs/design folder contains records of the major decisions in the design of the API. Most notably:
- Object construction is based on the fluent builder pattern.
- Nested objects can be constructed with builder lambdas, allowing for clean and expressive DSL-like code.
- Optional values are represented as
nullwith@Nullableannotations instead of the newerOptional, the Java ecosystem being still very null-based.
While still a work in progress, this library is published on a private Maven repository hosted on GitHub Packages.
It can be added to a Gradle project (Groovy flavor) as follows:
repositories { mavenCentral() maven { name = "GitHubPackages" url = uri("https://maven.pkg.github.com/elastic/elasticsearch-java") credentials { username = project.findProperty("gpr.user") ?: System.getenv("GITHUB_USERNAME") password = project.findProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN") } } } dependencies { implementation 'co.elastic.clients:elasticsearch-java:8.0.0-SNAPSHOT' }// Create the low-level client RestClient restClient = RestClient.builder(new HttpHost("localhost", 9200)).build(); // Create the transport (this may not be needed in the future) Transport transport = new Transport(restClient); // Build the high-level client ElasticsearchClient client = new ElasticsearchClient(transport); // Search all items in an index SearchResponse search = client.search(s -> s .index("test-index") ); if (search.hits().hits().isEmpty()) { System.out.println("No match"); } else { //... }