OpenSearch Java Client
opensearch-java is a community-driven, open source fork of elasticsearch-java licensed under the Apache v2.0 License. For more information, see opensearch.org. This client is meant to replace the existing OpenSearch Java High Level REST Client.
Note: This project is in beta stage and is for testing and feedback purposes only.
- Project Website
- Downloads.
- Documentation
- Need help? Try Forums
- Project Principles
- Contributing to OpenSearch
- Maintainer Responsibilities
- Release Management
- Admin Responsibilities
- Security
- Set
JAVA_HOME
to point to a JDK >= 11 - Checkout and build the opensearch-java project.
git clone https://github.com/opensearch-project/opensearch-java.git
cd opensearch-java
./gradlew build
- Launch Intellij IDEA, choose Import Project, and select the
settings.gradle.kts
file in the root of this project.
try (RestClient restClient = RestClient.builder(new HttpHost("localhost", 9200)).build()) {
String index = "test-index";
// Create Client
Transport transport = new RestClientTransport(restClient, new JacksonJsonpMapper());
OpenSearchClient client = new OpenSearchClient(transport);
// Create Index
CreateRequest createIndexRequest = new CreateRequest.Builder().index(index).build();
CreateResponse createIndexResponse = client.indices().create(createIndexRequest);
assert createIndexResponse.acknowledged();
// Index Document
IndexData indexData = new IndexData("foo", "bar");
IndexRequest<IndexData> indexRequest = new IndexRequest.Builder<IndexData>().index(index).id("1").value(indexData).build();
IndexResponse indexResponse = client.index(indexRequest);
assert Objects.equals(indexResponse.id(), "1");
// Search Documents
SearchResponse<IndexData> searchResponse = client.search(s -> s.index(index), IndexData.class);
assert !searchResponse.hits().hits().isEmpty();
searchResponse.hits().hits().stream().map(Hit::source).forEach(System.out::println);
// Delete Index
DeleteRequest deleteRequest = new DeleteRequest.Builder().index(index).build();
DeleteResponse deleteResponse = client.indices().delete(deleteRequest);
assert deleteResponse.acknowledged();
}
This project has adopted the Amazon Open Source Code of Conduct. For more information see the Code of Conduct FAQ, or contact [email protected] with any additional questions or comments.
This project is licensed under the Apache v2.0 License.
Copyright 2020-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.