Complete EnrichIT by using the execute enrich policy API (#42433)
This commit is contained in:
parent
2325ffb757
commit
5901285773
|
@ -5,20 +5,14 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.enrich;
|
||||
|
||||
import org.apache.http.entity.ByteArrayEntity;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.elasticsearch.client.Request;
|
||||
import org.elasticsearch.client.Response;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.test.rest.ESRestTestCase;
|
||||
import org.junit.After;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -38,34 +32,24 @@ public class EnrichIT extends ESRestTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: update this test when policy runner is ready
|
||||
public void testBasicFlow() throws Exception {
|
||||
// Create the policy:
|
||||
Request putPolicyRequest = new Request("PUT", "/_enrich/policy/my_policy");
|
||||
putPolicyRequest.setJsonEntity("{\"type\": \"exact_match\",\"indices\": [\"my-index*\"], \"enrich_key\": \"host\", " +
|
||||
putPolicyRequest.setJsonEntity("{\"type\": \"exact_match\",\"indices\": [\"my-source-index\"], \"enrich_key\": \"host\", " +
|
||||
"\"enrich_values\": [\"globalRank\", \"tldRank\", \"tld\"]}");
|
||||
assertOK(client().performRequest(putPolicyRequest));
|
||||
|
||||
// create index (remove when execute policy api has been added)
|
||||
String mapping = "\"_meta\": {\"enrich_key_field\": \"host\"}";
|
||||
createIndex(".enrich-my_policy", Settings.EMPTY, mapping);
|
||||
|
||||
// Add a single enrich document for now and then refresh:
|
||||
Request indexRequest = new Request("PUT", "/.enrich-my_policy/_doc/elastic.co");
|
||||
XContentBuilder document = XContentBuilder.builder(XContentType.SMILE.xContent());
|
||||
document.startObject();
|
||||
document.field("host", "elastic.co");
|
||||
document.field("globalRank", 25);
|
||||
document.field("tldRank", 7);
|
||||
document.field("tld", "co");
|
||||
document.endObject();
|
||||
document.close();
|
||||
ByteArrayOutputStream out = (ByteArrayOutputStream) document.getOutputStream();
|
||||
indexRequest.setEntity(new ByteArrayEntity(out.toByteArray(), ContentType.create("application/smile")));
|
||||
// Add entry to source index and then refresh:
|
||||
Request indexRequest = new Request("PUT", "/my-source-index/_doc/elastic.co");
|
||||
indexRequest.setJsonEntity("{\"host\": \"elastic.co\",\"globalRank\": 25,\"tldRank\": 7,\"tld\": \"co\"}");
|
||||
assertOK(client().performRequest(indexRequest));
|
||||
Request refreshRequest = new Request("POST", "/.enrich-my_policy/_refresh");
|
||||
Request refreshRequest = new Request("POST", "/my-source-index/_refresh");
|
||||
assertOK(client().performRequest(refreshRequest));
|
||||
|
||||
// Execute the policy:
|
||||
Request executePolicyRequest = new Request("POST", "/_enrich/policy/my_policy/_execute");
|
||||
assertOK(client().performRequest(executePolicyRequest));
|
||||
|
||||
// Create pipeline
|
||||
Request putPipelineRequest = new Request("PUT", "/_ingest/pipeline/my_pipeline");
|
||||
putPipelineRequest.setJsonEntity("{\"processors\":[" +
|
||||
|
@ -90,10 +74,6 @@ public class EnrichIT extends ESRestTestCase {
|
|||
assertThat(_source.get("host"), equalTo("elastic.co"));
|
||||
assertThat(_source.get("global_rank"), equalTo(25));
|
||||
assertThat(_source.get("tld_rank"), equalTo(7));
|
||||
|
||||
// Delete policy:
|
||||
Request deletePolicyRequest = new Request("DELETE", "/_enrich/policy/my_policy");
|
||||
assertOK(client().performRequest(deletePolicyRequest));
|
||||
}
|
||||
|
||||
private static Map<String, Object> toMap(Response response) throws IOException {
|
||||
|
|
Loading…
Reference in New Issue