Skip to content

imRishN/opensearch-java

 
 

Code style and license headers Build Chat PRs welcome!

OpenSearch logo

OpenSearch Java Client

Welcome!

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 Resources

Setup

  1. Set JAVA_HOME to point to a JDK >= 11
  2. Checkout and build the opensearch-java project.
git clone https://github.com/opensearch-project/opensearch-java.git
cd opensearch-java
./gradlew build
  1. Launch Intellij IDEA, choose Import Project, and select the settings.gradle.kts file in the root of this project.

Example

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();
}

Code of Conduct

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.

License

This project is licensed under the Apache v2.0 License.

Copyright

Copyright 2020-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.

About

Java High level Client for OpenSearch

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 99.7%
  • Other 0.3%