Correcting the java client code snippets and updating java client version (#4789)

Signed-off-by: Vacha Shah <vachshah@amazon.com>
This commit is contained in:
Vacha Shah 2023-08-15 13:00:32 -07:00 committed by GitHub
parent df2b573e46
commit 476e2d6422
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 46 additions and 61 deletions

View File

@ -18,7 +18,7 @@ To start using the OpenSearch Java client, you need to provide a transport. The
<dependency> <dependency>
<groupId>org.opensearch.client</groupId> <groupId>org.opensearch.client</groupId>
<artifactId>opensearch-java</artifactId> <artifactId>opensearch-java</artifactId>
<version>2.4.0</version> <version>2.6.0</version>
</dependency> </dependency>
``` ```
{% include copy.html %} {% include copy.html %}
@ -27,7 +27,7 @@ If you're using Gradle, add the following dependencies to your project:
``` ```
dependencies { dependencies {
implementation 'org.opensearch.client:opensearch-java:2.4.0' implementation 'org.opensearch.client:opensearch-java:2.6.0'
} }
``` ```
{% include copy.html %} {% include copy.html %}
@ -48,7 +48,7 @@ Alternatively, you can create a Java client by using the `RestClient`-based tran
<dependency> <dependency>
<groupId>org.opensearch.client</groupId> <groupId>org.opensearch.client</groupId>
<artifactId>opensearch-java</artifactId> <artifactId>opensearch-java</artifactId>
<version>2.4.0</version> <version>2.6.0</version>
</dependency> </dependency>
``` ```
{% include copy.html %} {% include copy.html %}
@ -58,7 +58,7 @@ If you're using Gradle, add the following dependencies to your project"
``` ```
dependencies { dependencies {
implementation 'org.opensearch.client:opensearch-rest-client:{{site.opensearch_version}}' implementation 'org.opensearch.client:opensearch-rest-client:{{site.opensearch_version}}'
implementation 'org.opensearch.client:opensearch-java:2.4.0' implementation 'org.opensearch.client:opensearch-java:2.6.0'
} }
``` ```
{% include copy.html %} {% include copy.html %}
@ -291,7 +291,7 @@ You can create an index with non-default settings using the following code:
```java ```java
String index = "sample-index"; String index = "sample-index";
CreateRequest createIndexRequest = new CreateRequest.Builder().index(index).build(); CreateIndexRequest createIndexRequest = new CreateIndexRequest.Builder().index(index).build();
client.indices().create(createIndexRequest); client.indices().create(createIndexRequest);
IndexSettings indexSettings = new IndexSettings.Builder().autoExpandReplicas("0-all").build(); IndexSettings indexSettings = new IndexSettings.Builder().autoExpandReplicas("0-all").build();
@ -338,22 +338,8 @@ client.delete(b -> b.index(index).id("1"));
The following sample code deletes an index: The following sample code deletes an index:
```java ```java
DeleteRequest deleteRequest = new DeleteRequest.Builder().index(index).build(); DeleteIndexRequest deleteIndexRequest = new DeleteRequest.Builder().index(index).build();
DeleteResponse deleteResponse = client.indices().delete(deleteRequest); DeleteIndexResponse deleteIndexResponse = client.indices().delete(deleteIndexRequest);
} catch (IOException e){
System.out.println(e.toString());
} finally {
try {
if (restClient != null) {
restClient.close();
}
} catch (IOException e) {
System.out.println(e.toString());
}
}
}
}
``` ```
{% include copy.html %} {% include copy.html %}
@ -407,7 +393,7 @@ public class OpenSearchClientExample {
//Create the index //Create the index
String index = "sample-index"; String index = "sample-index";
CreateRequest createIndexRequest = new CreateRequest.Builder().index(index).build(); CreateIndexRequest createIndexRequest = new CreateIndexRequest.Builder().index(index).build();
client.indices().create(createIndexRequest); client.indices().create(createIndexRequest);
//Add some settings to the index //Add some settings to the index
@ -431,9 +417,8 @@ public class OpenSearchClientExample {
client.delete(b -> b.index(index).id("1")); client.delete(b -> b.index(index).id("1"));
// Delete the index // Delete the index
DeleteRequest deleteRequest = new DeleteRequest.Builder().index(index).build(); DeleteIndexRequest deleteIndexRequest = new DeleteRequest.Builder().index(index).build();
DeleteResponse deleteResponse = client.indices().delete(deleteRequest); DeleteIndexResponse deleteIndexResponse = client.indices().delete(deleteIndexRequest);
} catch (IOException e){ } catch (IOException e){
System.out.println(e.toString()); System.out.println(e.toString());
} finally { } finally {