|
@@ -24,7 +24,9 @@ import org.elasticsearch.client.ESRestHighLevelClientTestCase;
|
|
|
import org.elasticsearch.client.RequestOptions;
|
|
|
import org.elasticsearch.client.RestHighLevelClient;
|
|
|
import org.elasticsearch.client.core.AcknowledgedResponse;
|
|
|
+import org.elasticsearch.client.enrich.DeletePolicyRequest;
|
|
|
import org.elasticsearch.client.enrich.PutPolicyRequest;
|
|
|
+import org.junit.After;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.concurrent.CountDownLatch;
|
|
@@ -32,6 +34,17 @@ import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
public class EnrichDocumentationIT extends ESRestHighLevelClientTestCase {
|
|
|
|
|
|
+ @After
|
|
|
+ public void cleanup() {
|
|
|
+ RestHighLevelClient client = highLevelClient();
|
|
|
+ DeletePolicyRequest deletePolicyRequest = new DeletePolicyRequest("users-policy");
|
|
|
+ try {
|
|
|
+ client.enrich().deletePolicy(deletePolicyRequest, RequestOptions.DEFAULT);
|
|
|
+ } catch (Exception e) {
|
|
|
+ // ignore... it is ok if policy has already been removed
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public void testPutPolicy() throws Exception {
|
|
|
RestHighLevelClient client = highLevelClient();
|
|
|
// tag::enrich-put-policy-request
|
|
@@ -54,8 +67,7 @@ public class EnrichDocumentationIT extends ESRestHighLevelClientTestCase {
|
|
|
ActionListener<AcknowledgedResponse> listener = new ActionListener<>() {
|
|
|
@Override
|
|
|
public void onResponse(AcknowledgedResponse response) { // <1>
|
|
|
- boolean isAcknowledged =
|
|
|
- putPolicyResponse.isAcknowledged();
|
|
|
+ boolean isAcknowledged = response.isAcknowledged();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -77,4 +89,56 @@ public class EnrichDocumentationIT extends ESRestHighLevelClientTestCase {
|
|
|
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
|
|
}
|
|
|
|
|
|
+ public void testDeletePolicy() throws Exception {
|
|
|
+ RestHighLevelClient client = highLevelClient();
|
|
|
+
|
|
|
+ {
|
|
|
+ // Add a policy, so that it can be deleted:
|
|
|
+ PutPolicyRequest putPolicyRequest = new PutPolicyRequest(
|
|
|
+ "users-policy", "exact_match", List.of("users"),
|
|
|
+ "email", List.of("address", "zip", "city", "state"));
|
|
|
+ client.enrich().putPolicy(putPolicyRequest, RequestOptions.DEFAULT);
|
|
|
+ }
|
|
|
+
|
|
|
+ // tag::enrich-delete-policy-request
|
|
|
+ DeletePolicyRequest deletePolicyRequest =
|
|
|
+ new DeletePolicyRequest("users-policy");
|
|
|
+ // end::enrich-delete-policy-request
|
|
|
+
|
|
|
+ // tag::enrich-delete-policy-execute
|
|
|
+ AcknowledgedResponse deletePolicyResponse = client.enrich()
|
|
|
+ .deletePolicy(deletePolicyRequest, RequestOptions.DEFAULT);
|
|
|
+ // end::enrich-delete-policy-execute
|
|
|
+
|
|
|
+ // tag::enrich-delete-policy-response
|
|
|
+ boolean isAcknowledged =
|
|
|
+ deletePolicyResponse.isAcknowledged(); // <1>
|
|
|
+ // end::enrich-delete-policy-response
|
|
|
+
|
|
|
+ // tag::enrich-delete-policy-execute-listener
|
|
|
+ ActionListener<AcknowledgedResponse> listener = new ActionListener<>() {
|
|
|
+ @Override
|
|
|
+ public void onResponse(AcknowledgedResponse response) { // <1>
|
|
|
+ boolean isAcknowledged = response.isAcknowledged();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFailure(Exception e) {
|
|
|
+ // <2>
|
|
|
+ }
|
|
|
+ };
|
|
|
+ // end::enrich-delete-policy-execute-listener
|
|
|
+
|
|
|
+ // Replace the empty listener by a blocking listener in test
|
|
|
+ final CountDownLatch latch = new CountDownLatch(1);
|
|
|
+ listener = new LatchedActionListener<>(listener, latch);
|
|
|
+
|
|
|
+ // tag::enrich-delete-policy-execute-async
|
|
|
+ client.enrich().deletePolicyAsync(deletePolicyRequest,
|
|
|
+ RequestOptions.DEFAULT, listener); // <1>
|
|
|
+ // end::enrich-delete-policy-execute-async
|
|
|
+
|
|
|
+ assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
|
|
+ }
|
|
|
+
|
|
|
}
|