Code Monkey home page Code Monkey logo

opensearch-java's Introduction

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.

opensearch-java's People

Contributors

gaiksaya avatar imrishn avatar mitalawachat avatar philkra avatar reta avatar sothawo avatar swallez avatar vijayanb avatar zelinh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.