From 09c42690971682f3045988b554f8f14d3ebd9e91 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Wed, 27 Nov 2019 07:52:42 +0100 Subject: [PATCH] Add templating support to enrich processor (#49093) Adds support for templating to `field` and `target_field` options. --- .../ingest/processors/enrich.asciidoc | 4 +- .../ingest/ConfigurationUtils.java | 6 +++ x-pack/plugin/enrich/build.gradle | 1 + .../xpack/enrich/AbstractEnrichProcessor.java | 24 ++++++----- .../xpack/enrich/EnrichPlugin.java | 2 +- .../xpack/enrich/EnrichProcessorFactory.java | 10 +++-- .../xpack/enrich/GeoMatchProcessor.java | 9 +++-- .../xpack/enrich/MatchProcessor.java | 9 +++-- .../xpack/enrich/BasicEnrichTests.java | 40 ++++++++++++++++++- .../enrich/EnrichProcessorFactoryTests.java | 24 +++++++---- .../xpack/enrich/GeoMatchProcessorTests.java | 5 ++- .../xpack/enrich/MatchProcessorTests.java | 38 +++++++++++++----- 12 files changed, 128 insertions(+), 44 deletions(-) diff --git a/docs/reference/ingest/processors/enrich.asciidoc b/docs/reference/ingest/processors/enrich.asciidoc index 3f6ad009d4a..f9766261f4b 100644 --- a/docs/reference/ingest/processors/enrich.asciidoc +++ b/docs/reference/ingest/processors/enrich.asciidoc @@ -12,8 +12,8 @@ See <> section for more information about how |====== | Name | Required | Default | Description | `policy_name` | yes | - | The name of the enrich policy to use. -| `field` | yes | - | The field in the input document that matches the policies match_field used to retrieve the enrichment data. -| `target_field` | yes | - | The field that will be used for the enrichment data. +| `field` | yes | - | The field in the input document that matches the policies match_field used to retrieve the enrichment data. Supports <>. +| `target_field` | yes | - | The field that will be used for the enrichment data. Supports <>. | `ignore_missing` | no | false | If `true` and `field` does not exist, the processor quietly exits without modifying the document | `override` | no | true | If processor will update fields with pre-existing non-null-valued field. When set to `false`, such fields will not be touched. | `max_matches` | no | 1 | The maximum number of matched documents to include under the configured target field. The `target_field` will be turned into a json array if `max_matches` is higher than 1, otherwise `target_field` will become a json object. In order to avoid documents getting too large, the maximum allowed value is 128. diff --git a/server/src/main/java/org/elasticsearch/ingest/ConfigurationUtils.java b/server/src/main/java/org/elasticsearch/ingest/ConfigurationUtils.java index c725157d8de..c2a5b09cd53 100644 --- a/server/src/main/java/org/elasticsearch/ingest/ConfigurationUtils.java +++ b/server/src/main/java/org/elasticsearch/ingest/ConfigurationUtils.java @@ -348,6 +348,12 @@ public final class ConfigurationUtils { return processors; } + public static TemplateScript.Factory readTemplateProperty(String processorType, String processorTag, Map configuration, + String propertyName, ScriptService scriptService) { + String value = readStringProperty(processorType, processorTag, configuration, propertyName, null); + return compileTemplate(processorType, processorTag, propertyName, value, scriptService); + } + public static TemplateScript.Factory compileTemplate(String processorType, String processorTag, String propertyName, String propertyValue, ScriptService scriptService) { try { diff --git a/x-pack/plugin/enrich/build.gradle b/x-pack/plugin/enrich/build.gradle index d216a8bbaca..12ca16115f8 100644 --- a/x-pack/plugin/enrich/build.gradle +++ b/x-pack/plugin/enrich/build.gradle @@ -13,6 +13,7 @@ dependencies { compileOnly project(path: xpackModule('core'), configuration: 'default') testCompile project(path: xpackModule('core'), configuration: 'testArtifacts') testCompile project(path: ':modules:ingest-common') + testCompile project(path: ':modules:lang-mustache') testCompile project(path: xpackModule('monitoring'), configuration: 'testArtifacts') } diff --git a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/AbstractEnrichProcessor.java b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/AbstractEnrichProcessor.java index 6b77a096ea7..e622187be20 100644 --- a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/AbstractEnrichProcessor.java +++ b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/AbstractEnrichProcessor.java @@ -14,12 +14,14 @@ import org.elasticsearch.index.query.ConstantScoreQueryBuilder; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.ingest.AbstractProcessor; import org.elasticsearch.ingest.IngestDocument; +import org.elasticsearch.script.TemplateScript; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.xpack.core.enrich.EnrichPolicy; import org.elasticsearch.xpack.enrich.action.EnrichCoordinatorProxyAction; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.function.BiConsumer; @@ -28,8 +30,8 @@ public abstract class AbstractEnrichProcessor extends AbstractProcessor { private final String policyName; private final BiConsumer> searchRunner; - private final String field; - private final String targetField; + private final TemplateScript.Factory field; + private final TemplateScript.Factory targetField; private final boolean ignoreMissing; private final boolean overrideEnabled; protected final String matchField; @@ -39,8 +41,8 @@ public abstract class AbstractEnrichProcessor extends AbstractProcessor { String tag, Client client, String policyName, - String field, - String targetField, + TemplateScript.Factory field, + TemplateScript.Factory targetField, boolean ignoreMissing, boolean overrideEnabled, String matchField, @@ -53,8 +55,8 @@ public abstract class AbstractEnrichProcessor extends AbstractProcessor { String tag, BiConsumer> searchRunner, String policyName, - String field, - String targetField, + TemplateScript.Factory field, + TemplateScript.Factory targetField, boolean ignoreMissing, boolean overrideEnabled, String matchField, @@ -77,6 +79,7 @@ public abstract class AbstractEnrichProcessor extends AbstractProcessor { public void execute(IngestDocument ingestDocument, BiConsumer handler) { try { // If a document does not have the enrich key, return the unchanged document + String field = ingestDocument.renderTemplate(this.field); final Object value = ingestDocument.getFieldValue(field, Object.class, ignoreMissing); if (value == null) { handler.accept(ingestDocument, null); @@ -111,6 +114,7 @@ public abstract class AbstractEnrichProcessor extends AbstractProcessor { return; } + String targetField = ingestDocument.renderTemplate(this.targetField); if (overrideEnabled || ingestDocument.hasField(targetField) == false) { if (maxMatches == 1) { Map firstDocument = searchHits[0].getSourceAsMap(); @@ -146,11 +150,13 @@ public abstract class AbstractEnrichProcessor extends AbstractProcessor { } String getField() { - return field; + // used for testing only: + return field.newInstance(Collections.emptyMap()).execute(); } - public String getTargetField() { - return targetField; + String getTargetField() { + // used for testing only: + return targetField.newInstance(Collections.emptyMap()).execute(); } boolean isIgnoreMissing() { diff --git a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPlugin.java b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPlugin.java index a80f06d304b..030966dc8d1 100644 --- a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPlugin.java +++ b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPlugin.java @@ -138,7 +138,7 @@ public class EnrichPlugin extends Plugin implements ActionPlugin, IngestPlugin { return emptyMap(); } - EnrichProcessorFactory factory = new EnrichProcessorFactory(parameters.client); + EnrichProcessorFactory factory = new EnrichProcessorFactory(parameters.client, parameters.scriptService); parameters.ingestService.addIngestClusterStateListener(factory); return Collections.singletonMap(EnrichProcessorFactory.TYPE, factory); } diff --git a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichProcessorFactory.java b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichProcessorFactory.java index 0cd89959236..96d9efadde7 100644 --- a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichProcessorFactory.java +++ b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichProcessorFactory.java @@ -14,6 +14,8 @@ import org.elasticsearch.common.geo.ShapeRelation; import org.elasticsearch.common.xcontent.support.XContentMapValues; import org.elasticsearch.ingest.ConfigurationUtils; import org.elasticsearch.ingest.Processor; +import org.elasticsearch.script.ScriptService; +import org.elasticsearch.script.TemplateScript; import org.elasticsearch.xpack.core.enrich.EnrichPolicy; import java.util.Map; @@ -23,11 +25,13 @@ final class EnrichProcessorFactory implements Processor.Factory, Consumer mappingAsMap = imd.mapping().sourceAsMap(); String policyType = (String) XContentMapValues.extractValue( "_meta." + EnrichPolicyRunner.ENRICH_POLICY_TYPE_FIELD_NAME, @@ -50,9 +53,10 @@ final class EnrichProcessorFactory implements Processor.Factory, Consumer 128) { throw ConfigurationUtils.newConfigurationException(TYPE, tag, "max_matches", "should be between 1 and 128"); diff --git a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/GeoMatchProcessor.java b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/GeoMatchProcessor.java index 73d224d74ec..b10bafa5e95 100644 --- a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/GeoMatchProcessor.java +++ b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/GeoMatchProcessor.java @@ -16,6 +16,7 @@ import org.elasticsearch.geometry.MultiPoint; import org.elasticsearch.geometry.Point; import org.elasticsearch.index.query.GeoShapeQueryBuilder; import org.elasticsearch.index.query.QueryBuilder; +import org.elasticsearch.script.TemplateScript; import java.util.ArrayList; import java.util.List; @@ -29,8 +30,8 @@ public final class GeoMatchProcessor extends AbstractEnrichProcessor { String tag, Client client, String policyName, - String field, - String targetField, + TemplateScript.Factory field, + TemplateScript.Factory targetField, boolean overrideEnabled, boolean ignoreMissing, String matchField, @@ -46,8 +47,8 @@ public final class GeoMatchProcessor extends AbstractEnrichProcessor { String tag, BiConsumer> searchRunner, String policyName, - String field, - String targetField, + TemplateScript.Factory field, + TemplateScript.Factory targetField, boolean overrideEnabled, boolean ignoreMissing, String matchField, diff --git a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/MatchProcessor.java b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/MatchProcessor.java index 44cef89fe9b..6e2967272fa 100644 --- a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/MatchProcessor.java +++ b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/MatchProcessor.java @@ -11,6 +11,7 @@ import org.elasticsearch.client.Client; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.TermQueryBuilder; import org.elasticsearch.index.query.TermsQueryBuilder; +import org.elasticsearch.script.TemplateScript; import java.util.List; import java.util.function.BiConsumer; @@ -21,8 +22,8 @@ public class MatchProcessor extends AbstractEnrichProcessor { String tag, Client client, String policyName, - String field, - String targetField, + TemplateScript.Factory field, + TemplateScript.Factory targetField, boolean overrideEnabled, boolean ignoreMissing, String matchField, @@ -36,8 +37,8 @@ public class MatchProcessor extends AbstractEnrichProcessor { String tag, BiConsumer> searchRunner, String policyName, - String field, - String targetField, + TemplateScript.Factory field, + TemplateScript.Factory targetField, boolean overrideEnabled, boolean ignoreMissing, String matchField, diff --git a/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/BasicEnrichTests.java b/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/BasicEnrichTests.java index ce98f698a27..3d0e30198ba 100644 --- a/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/BasicEnrichTests.java +++ b/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/BasicEnrichTests.java @@ -22,6 +22,7 @@ import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.reindex.ReindexPlugin; import org.elasticsearch.ingest.common.IngestCommonPlugin; import org.elasticsearch.plugins.Plugin; +import org.elasticsearch.script.mustache.MustachePlugin; import org.elasticsearch.test.ESSingleNodeTestCase; import org.elasticsearch.xpack.core.enrich.EnrichPolicy; import org.elasticsearch.xpack.core.enrich.action.EnrichStatsAction; @@ -53,7 +54,7 @@ public class BasicEnrichTests extends ESSingleNodeTestCase { @Override protected Collection> getPlugins() { - return Arrays.asList(LocalStateEnrich.class, ReindexPlugin.class, IngestCommonPlugin.class); + return Arrays.asList(LocalStateEnrich.class, ReindexPlugin.class, IngestCommonPlugin.class, MustachePlugin.class); } @Override @@ -313,6 +314,43 @@ public class BasicEnrichTests extends ESSingleNodeTestCase { } } + public void testTemplating() throws Exception { + List keys = createSourceMatchIndex(1, 1); + String policyName = "my-policy"; + EnrichPolicy enrichPolicy = new EnrichPolicy( + EnrichPolicy.MATCH_TYPE, + null, + Collections.singletonList(SOURCE_INDEX_NAME), + MATCH_FIELD, + Arrays.asList(DECORATE_FIELDS) + ); + PutEnrichPolicyAction.Request request = new PutEnrichPolicyAction.Request(policyName, enrichPolicy); + client().execute(PutEnrichPolicyAction.INSTANCE, request).actionGet(); + client().execute(ExecuteEnrichPolicyAction.INSTANCE, new ExecuteEnrichPolicyAction.Request(policyName)).actionGet(); + + String pipelineName = "my-pipeline"; + String pipelineBody = "{\"processors\": [{\"enrich\": {\"policy_name\":\"" + + policyName + + "\", \"field\": \"{{indirection1}}\", \"target_field\": \"{{indirection2}}\"" + + "}}]}"; + PutPipelineRequest putPipelineRequest = new PutPipelineRequest(pipelineName, new BytesArray(pipelineBody), XContentType.JSON); + client().admin().cluster().putPipeline(putPipelineRequest).actionGet(); + + IndexRequest indexRequest = new IndexRequest("my-index").id("1") + .setPipeline(pipelineName) + .source(mapOf("indirection1", MATCH_FIELD, "indirection2", "users", MATCH_FIELD, keys.get(0))); + client().index(indexRequest).get(); + GetResponse getResponse = client().get(new GetRequest("my-index", "1")).actionGet(); + Map source = getResponse.getSourceAsMap(); + Map userEntry = (Map) source.get("users"); + assertThat(userEntry.size(), equalTo(DECORATE_FIELDS.length + 1)); + for (int j = 0; j < 3; j++) { + String field = DECORATE_FIELDS[j]; + assertThat(userEntry.get(field), equalTo(keys.get(0) + j)); + } + assertThat(keys.contains(userEntry.get(MATCH_FIELD)), is(true)); + } + private List createSourceMatchIndex(int numKeys, int numDocsPerKey) { Set keys = new HashSet<>(); for (int id = 0; id < numKeys; id++) { diff --git a/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/EnrichProcessorFactoryTests.java b/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/EnrichProcessorFactoryTests.java index c3e71455470..1ec556d759f 100644 --- a/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/EnrichProcessorFactoryTests.java +++ b/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/EnrichProcessorFactoryTests.java @@ -12,8 +12,10 @@ import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.script.ScriptService; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.enrich.EnrichPolicy; +import org.junit.Before; import java.io.IOException; import java.util.ArrayList; @@ -26,9 +28,17 @@ import java.util.Map; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; +import static org.mockito.Mockito.mock; public class EnrichProcessorFactoryTests extends ESTestCase { + private ScriptService scriptService; + + @Before + public void initializeScriptService() { + scriptService = mock(ScriptService.class); + } + public void testCreateProcessorInstance() throws Exception { List enrichValues = Arrays.asList("globalRank", "tldRank", "tld"); EnrichPolicy policy = new EnrichPolicy( @@ -38,7 +48,7 @@ public class EnrichProcessorFactoryTests extends ESTestCase { "my_key", enrichValues ); - EnrichProcessorFactory factory = new EnrichProcessorFactory(null); + EnrichProcessorFactory factory = new EnrichProcessorFactory(null, scriptService); factory.metaData = createMetaData("majestic", policy); Map config = new HashMap<>(); @@ -88,7 +98,7 @@ public class EnrichProcessorFactoryTests extends ESTestCase { public void testPolicyDoesNotExist() { List enrichValues = Arrays.asList("globalRank", "tldRank", "tld"); - EnrichProcessorFactory factory = new EnrichProcessorFactory(null); + EnrichProcessorFactory factory = new EnrichProcessorFactory(null, scriptService); factory.metaData = MetaData.builder().build(); Map config = new HashMap<>(); @@ -120,7 +130,7 @@ public class EnrichProcessorFactoryTests extends ESTestCase { public void testPolicyNameMissing() { List enrichValues = Arrays.asList("globalRank", "tldRank", "tld"); - EnrichProcessorFactory factory = new EnrichProcessorFactory(null); + EnrichProcessorFactory factory = new EnrichProcessorFactory(null, scriptService); Map config = new HashMap<>(); config.put("enrich_key", "host"); @@ -151,7 +161,7 @@ public class EnrichProcessorFactoryTests extends ESTestCase { public void testUnsupportedPolicy() throws Exception { List enrichValues = Arrays.asList("globalRank", "tldRank", "tld"); EnrichPolicy policy = new EnrichPolicy("unsupported", null, Collections.singletonList("source_index"), "my_key", enrichValues); - EnrichProcessorFactory factory = new EnrichProcessorFactory(null); + EnrichProcessorFactory factory = new EnrichProcessorFactory(null, scriptService); factory.metaData = createMetaData("majestic", policy); Map config = new HashMap<>(); @@ -176,7 +186,7 @@ public class EnrichProcessorFactoryTests extends ESTestCase { "host", enrichValues ); - EnrichProcessorFactory factory = new EnrichProcessorFactory(null); + EnrichProcessorFactory factory = new EnrichProcessorFactory(null, scriptService); factory.metaData = createMetaData("majestic", policy); Map config = new HashMap<>(); @@ -200,7 +210,7 @@ public class EnrichProcessorFactoryTests extends ESTestCase { "host", enrichValues ); - EnrichProcessorFactory factory = new EnrichProcessorFactory(null); + EnrichProcessorFactory factory = new EnrichProcessorFactory(null, scriptService); factory.metaData = createMetaData("majestic", policy); Map config1 = new HashMap<>(); @@ -214,7 +224,7 @@ public class EnrichProcessorFactoryTests extends ESTestCase { public void testIllegalMaxMatches() throws Exception { List enrichValues = Arrays.asList("globalRank", "tldRank", "tld"); EnrichPolicy policy = new EnrichPolicy(EnrichPolicy.MATCH_TYPE, null, Arrays.asList("source_index"), "my_key", enrichValues); - EnrichProcessorFactory factory = new EnrichProcessorFactory(null); + EnrichProcessorFactory factory = new EnrichProcessorFactory(null, scriptService); factory.metaData = createMetaData("majestic", policy); Map config = new HashMap<>(); diff --git a/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/GeoMatchProcessorTests.java b/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/GeoMatchProcessorTests.java index ff8780ff3f5..d94c94b41f5 100644 --- a/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/GeoMatchProcessorTests.java +++ b/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/GeoMatchProcessorTests.java @@ -41,6 +41,7 @@ import java.util.Map; import java.util.function.BiConsumer; import static org.elasticsearch.xpack.enrich.MatchProcessorTests.mapOf; +import static org.elasticsearch.xpack.enrich.MatchProcessorTests.str; import static org.hamcrest.Matchers.emptyArray; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.instanceOf; @@ -70,8 +71,8 @@ public class GeoMatchProcessorTests extends ESTestCase { "_tag", mockSearch, "_name", - "location", - "entry", + str("location"), + str("entry"), false, false, "shape", diff --git a/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/MatchProcessorTests.java b/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/MatchProcessorTests.java index dbf7f9ba719..c7e26310dea 100644 --- a/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/MatchProcessorTests.java +++ b/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/MatchProcessorTests.java @@ -23,6 +23,8 @@ import org.elasticsearch.index.query.ConstantScoreQueryBuilder; import org.elasticsearch.index.query.TermQueryBuilder; import org.elasticsearch.index.query.TermsQueryBuilder; import org.elasticsearch.ingest.IngestDocument; +import org.elasticsearch.ingest.TestTemplateService; +import org.elasticsearch.script.TemplateScript; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHits; import org.elasticsearch.search.aggregations.Aggregations; @@ -50,7 +52,17 @@ public class MatchProcessorTests extends ESTestCase { public void testBasics() throws Exception { int maxMatches = randomIntBetween(1, 8); MockSearchFunction mockSearch = mockedSearchFunction(mapOf("elastic.co", mapOf("globalRank", 451, "tldRank", 23, "tld", "co"))); - MatchProcessor processor = new MatchProcessor("_tag", mockSearch, "_name", "domain", "entry", true, false, "domain", maxMatches); + MatchProcessor processor = new MatchProcessor( + "_tag", + mockSearch, + "_name", + str("domain"), + str("entry"), + true, + false, + "domain", + maxMatches + ); IngestDocument ingestDocument = new IngestDocument( "_index", "_type", @@ -95,7 +107,7 @@ public class MatchProcessorTests extends ESTestCase { public void testNoMatch() throws Exception { MockSearchFunction mockSearch = mockedSearchFunction(); - MatchProcessor processor = new MatchProcessor("_tag", mockSearch, "_name", "domain", "entry", true, false, "domain", 1); + MatchProcessor processor = new MatchProcessor("_tag", mockSearch, "_name", str("domain"), str("entry"), true, false, "domain", 1); IngestDocument ingestDocument = new IngestDocument( "_index", "_type", @@ -132,7 +144,7 @@ public class MatchProcessorTests extends ESTestCase { public void testSearchFailure() throws Exception { String indexName = ".enrich-_name"; MockSearchFunction mockSearch = mockedSearchFunction(new IndexNotFoundException(indexName)); - MatchProcessor processor = new MatchProcessor("_tag", mockSearch, "_name", "domain", "entry", true, false, "domain", 1); + MatchProcessor processor = new MatchProcessor("_tag", mockSearch, "_name", str("domain"), str("entry"), true, false, "domain", 1); IngestDocument ingestDocument = new IngestDocument( "_index", "_type", @@ -177,8 +189,8 @@ public class MatchProcessorTests extends ESTestCase { "_tag", mockedSearchFunction(), "_name", - "domain", - "entry", + str("domain"), + str("entry"), true, true, "domain", @@ -197,8 +209,8 @@ public class MatchProcessorTests extends ESTestCase { "_tag", mockedSearchFunction(), "_name", - "domain", - "entry", + str("domain"), + str("entry"), true, false, "domain", @@ -219,7 +231,7 @@ public class MatchProcessorTests extends ESTestCase { public void testExistingFieldWithOverrideDisabled() throws Exception { MockSearchFunction mockSearch = mockedSearchFunction(mapOf("elastic.co", mapOf("globalRank", 451, "tldRank", 23, "tld", "co"))); - MatchProcessor processor = new MatchProcessor("_tag", mockSearch, "_name", "domain", "entry", false, false, "domain", 1); + MatchProcessor processor = new MatchProcessor("_tag", mockSearch, "_name", str("domain"), str("entry"), false, false, "domain", 1); IngestDocument ingestDocument = new IngestDocument(new HashMap<>(mapOf("domain", "elastic.co", "tld", "tld")), mapOf()); IngestDocument[] resultHolder = new IngestDocument[1]; @@ -235,7 +247,7 @@ public class MatchProcessorTests extends ESTestCase { public void testExistingNullFieldWithOverrideDisabled() throws Exception { MockSearchFunction mockSearch = mockedSearchFunction(mapOf("elastic.co", mapOf("globalRank", 451, "tldRank", 23, "tld", "co"))); - MatchProcessor processor = new MatchProcessor("_tag", mockSearch, "_name", "domain", "entry", false, false, "domain", 1); + MatchProcessor processor = new MatchProcessor("_tag", mockSearch, "_name", str("domain"), str("entry"), false, false, "domain", 1); Map source = new HashMap<>(); source.put("domain", "elastic.co"); @@ -254,7 +266,7 @@ public class MatchProcessorTests extends ESTestCase { public void testNumericValue() { MockSearchFunction mockSearch = mockedSearchFunction(mapOf(2, mapOf("globalRank", 451, "tldRank", 23, "tld", "co"))); - MatchProcessor processor = new MatchProcessor("_tag", mockSearch, "_name", "domain", "entry", false, true, "domain", 1); + MatchProcessor processor = new MatchProcessor("_tag", mockSearch, "_name", str("domain"), str("entry"), false, true, "domain", 1); IngestDocument ingestDocument = new IngestDocument( "_index", "_type", @@ -290,7 +302,7 @@ public class MatchProcessorTests extends ESTestCase { MockSearchFunction mockSearch = mockedSearchFunction( mapOf(Arrays.asList("1", "2"), mapOf("globalRank", 451, "tldRank", 23, "tld", "co")) ); - MatchProcessor processor = new MatchProcessor("_tag", mockSearch, "_name", "domain", "entry", false, true, "domain", 1); + MatchProcessor processor = new MatchProcessor("_tag", mockSearch, "_name", str("domain"), str("entry"), false, true, "domain", 1); IngestDocument ingestDocument = new IngestDocument( "_index", "_type", @@ -406,6 +418,10 @@ public class MatchProcessorTests extends ESTestCase { ); } + static TemplateScript.Factory str(String stringLiteral) { + return new TestTemplateService.MockTemplateScript.Factory(stringLiteral); + } + static Map mapOf() { return Collections.emptyMap(); }