mirror of
https://github.com/iSharkFly-Docs/opensearch-docs-cn
synced 2025-02-09 19:54:41 +00:00
More code tweaks
Signed-off-by: keithhc2 <keithhc2@users.noreply.github.com>
This commit is contained in:
parent
a3ed129d15
commit
be6f1ee6c8
@ -196,13 +196,12 @@ client.delete(b -> b.index(index).id("1"));
|
|||||||
DeleteRequest deleteRequest = new DeleteRequest.Builder().index(index).build();
|
DeleteRequest deleteRequest = new DeleteRequest.Builder().index(index).build();
|
||||||
DeleteResponse deleteResponse = client.indices().delete(deleteRequest);
|
DeleteResponse deleteResponse = client.indices().delete(deleteRequest);
|
||||||
|
|
||||||
restClient.close();
|
|
||||||
} catch (IOException e){
|
} catch (IOException e){
|
||||||
System.out.println(e.toString());
|
System.out.println(e.toString());
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
if (client != null) {
|
if (restClient != null) {
|
||||||
client.close();
|
restClient.close();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println(e.toString());
|
System.out.println(e.toString());
|
||||||
@ -215,11 +214,29 @@ restClient.close();
|
|||||||
## Complete code sample
|
## Complete code sample
|
||||||
|
|
||||||
```java
|
```java
|
||||||
|
import org.apache.http.HttpHost;
|
||||||
|
import org.apache.http.auth.AuthScope;
|
||||||
|
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||||
|
import org.apache.http.client.CredentialsProvider;
|
||||||
|
import org.apache.http.impl.client.BasicCredentialsProvider;
|
||||||
|
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
|
||||||
|
import org.opensearch.client.RestClient;
|
||||||
|
import org.opensearch.client.RestClientBuilder;
|
||||||
|
import org.opensearch.client.base.RestClientTransport;
|
||||||
|
import org.opensearch.client.base.Transport;
|
||||||
|
import org.opensearch.client.json.jackson.JacksonJsonpMapper;
|
||||||
|
import org.opensearch.client.opensearch.OpenSearchClient;
|
||||||
|
import org.opensearch.client.opensearch._global.IndexRequest;
|
||||||
|
import org.opensearch.client.opensearch._global.IndexResponse;
|
||||||
|
import org.opensearch.client.opensearch._global.SearchResponse;
|
||||||
|
import org.opensearch.client.opensearch.indices.*;
|
||||||
|
import org.opensearch.client.opensearch.indices.put_settings.IndexSettingsBody;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class OpenSearchClientExample {
|
public class OpenSearchClientExample {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
RestClient restClient = null;
|
||||||
RestClient restClient = null;
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
System.setProperty("javax.net.ssl.trustStore", "/full/path/to/keystore");
|
System.setProperty("javax.net.ssl.trustStore", "/full/path/to/keystore");
|
||||||
System.setProperty("javax.net.ssl.trustStorePassword", "password-to-keystore");
|
System.setProperty("javax.net.ssl.trustStorePassword", "password-to-keystore");
|
||||||
@ -269,7 +286,6 @@ public class OpenSearchClientExample {
|
|||||||
DeleteRequest deleteRequest = new DeleteRequest.Builder().index(index).build();
|
DeleteRequest deleteRequest = new DeleteRequest.Builder().index(index).build();
|
||||||
DeleteResponse deleteResponse = client.indices().delete(deleteRequest);
|
DeleteResponse deleteResponse = client.indices().delete(deleteRequest);
|
||||||
|
|
||||||
restClient.close();
|
|
||||||
} catch (IOException e){
|
} catch (IOException e){
|
||||||
System.out.println(e.toString());
|
System.out.println(e.toString());
|
||||||
} finally {
|
} finally {
|
||||||
@ -283,6 +299,4 @@ public class OpenSearchClientExample {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
Loading…
x
Reference in New Issue
Block a user