Giter Club home page Giter Club logo

opensearch-java-client-demo's Introduction

OpenSearch Java Client Demo

Makes requests to Amazon OpenSearch using the OpenSearch Java Client with native AWS SDK 2.0 transport support added in opensarch-java 2.1.0. Supports OpenSearch Serverless since opensearch-java 2.2.0.

For support with older versions and for using OpenSearch High Level REST Client directly, see opensearch-1.x or opensearch-2.x.

Running

Create an OpenSearch domain in (AWS) which support IAM based AuthN/AuthZ.

export AWS_ACCESS_KEY_ID=
export AWS_SECRET_ACCESS_KEY=
export AWS_SESSION_TOKEN=
export AWS_REGION=us-west-2

export SERVICE=es # use "aoss" for OpenSearch Serverless
export ENDPOINT=https://....us-west-2.es.amazonaws.com

mvn install
mvn compile exec:java \
  -Dexec.mainClass="Example" \
  -Dlog4j.configurationFile=target/log4j2.xml \
  -Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog \
  -Dorg.apache.commons.logging.simplelog.log.org.apache.http.wire=INFO

The code will show the server version, create an index, add a document, search for it, output the result, then cleanup.

2022-12-26 15:55:02 [Example.main()] INFO  - opensearch: 2.3.0
2022-12-26 15:55:04 [Example.main()] INFO  - Movie{Director='Bennett Miller', Title='Moneyball', Year=2011}

A sample that performs a vector (k-nn) search is also available in src/main/java/Knn.java.

mvn compile exec:java \
  -Dexec.mainClass="Knn" \
  -Dlog4j.configurationFile=target/log4j2.xml \
  -Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog \
  -Dorg.apache.commons.logging.simplelog.log.org.apache.http.wire=INFO

A sample that uses a generic client (raw JSON) is also available in src/main/java/Generic.java.

mvn compile exec:java \
  -Dexec.mainClass="Generic" \
  -Dlog4j.configurationFile=target/log4j2.xml \
  -Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog \
  -Dorg.apache.commons.logging.simplelog.log.org.apache.http.wire=INFO

A sample that uses dynamic proxy to intercept calls to OpenSearchClient so you can write cross-cutting concerns (such as logging, error handling or custom retry policies, etc.) once is also available in src/main/java/LoggingClientExample.java.

mvn compile exec:java \
  -Dexec.mainClass="LoggingClientExample" \
  -Dlog4j.configurationFile=target/log4j2.xml \
  -Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog \
  -Dorg.apache.commons.logging.simplelog.log.org.apache.http.wire=INFO

License

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

Copyright

Copyright OpenSearch Contributors. See NOTICE for details.

opensearch-java-client-demo's People

Contributors

dblock avatar kumjiten avatar

Stargazers

Jie Li avatar Nick Root avatar Gustavo de la Cruz Tovar avatar Wali Morris avatar  avatar Richard Kolb avatar Pinglei Guo avatar

Watchers

 avatar

opensearch-java-client-demo's Issues

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.