From 7cdde5ff17812a3c24b3863ded4b5a8b0ad5e729 Mon Sep 17 00:00:00 2001 From: Sam Xiao Date: Tue, 27 Aug 2024 22:35:14 -0400 Subject: [PATCH 01/10] Adds example plugin for custom ingest processor Adds an example for creating a plugin with a simple custom ingest processor. The example processor repeats the value of an expected filed in a document, or ignores it if the expected field does not exist. Closes #111539 --- .../creating-classic-plugins.asciidoc | 5 +- .../examples/custom-processor/build.gradle | 21 +++++++ .../ExampleProcessorPlugin.java | 28 +++++++++ .../ExampleRepeatProcessor.java | 48 +++++++++++++++ ...ExampleProcessorClientYamlTestSuiteIT.java | 40 ++++++++++++ .../test/resthandler/10_basic.yml | 13 ++++ .../test/resthandler/20_process_document.yml | 61 +++++++++++++++++++ 7 files changed, 214 insertions(+), 2 deletions(-) create mode 100644 plugins/examples/custom-processor/build.gradle create mode 100644 plugins/examples/custom-processor/src/main/java/org/elasticsearch/example/customprocessor/ExampleProcessorPlugin.java create mode 100644 plugins/examples/custom-processor/src/main/java/org/elasticsearch/example/customprocessor/ExampleRepeatProcessor.java create mode 100644 plugins/examples/custom-processor/src/yamlRestTest/java/org/elasticsearch/example/customprocessor/ExampleProcessorClientYamlTestSuiteIT.java create mode 100644 plugins/examples/custom-processor/src/yamlRestTest/resources/rest-api-spec/test/resthandler/10_basic.yml create mode 100644 plugins/examples/custom-processor/src/yamlRestTest/resources/rest-api-spec/test/resthandler/20_process_document.yml diff --git a/docs/plugins/development/creating-classic-plugins.asciidoc b/docs/plugins/development/creating-classic-plugins.asciidoc index f3f62a11f2993..04a646d7262b4 100644 --- a/docs/plugins/development/creating-classic-plugins.asciidoc +++ b/docs/plugins/development/creating-classic-plugins.asciidoc @@ -32,12 +32,13 @@ for the plugin. If you need other resources, package them into a resources JAR. The {es} repository contains {es-repo}tree/main/plugins/examples[examples of plugins]. Some of these include: * a plugin with {es-repo}tree/main/plugins/examples/custom-settings[custom settings] +* a plugin with {es-repo}tree/main/plugins/examples/custom-processor[custom ingest processor] * adding {es-repo}tree/main/plugins/examples/rest-handler[custom rest endpoints] * adding a {es-repo}tree/main/plugins/examples/rescore[custom rescorer] * a script {es-repo}tree/main/plugins/examples/script-expert-scoring[implemented in Java] These examples provide the bare bones needed to get started. For more -information about how to write a plugin, we recommend looking at the +information about how to write a plugin, we recommend looking at the {es-repo}tree/main/plugins/[source code of existing plugins] for inspiration. [discrete] @@ -88,4 +89,4 @@ for more information. [[plugin-descriptor-file-classic]] ==== The plugin descriptor file for classic plugins -include::plugin-descriptor-file.asciidoc[] \ No newline at end of file +include::plugin-descriptor-file.asciidoc[] diff --git a/plugins/examples/custom-processor/build.gradle b/plugins/examples/custom-processor/build.gradle new file mode 100644 index 0000000000000..69da64d8ebe86 --- /dev/null +++ b/plugins/examples/custom-processor/build.gradle @@ -0,0 +1,21 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ +apply plugin: 'elasticsearch.esplugin' +apply plugin: 'elasticsearch.yaml-rest-test' + +esplugin { + name 'custom-processor' + description 'An example plugin showing how to register a custom ingest processor' + classname 'org.elasticsearch.example.customprocessor.ExampleProcessorPlugin' + licenseFile rootProject.file('SSPL-1.0+ELASTIC-LICENSE-2.0.txt') + noticeFile rootProject.file('NOTICE.txt') +} + +dependencies { + yamlRestTestRuntimeOnly "org.apache.logging.log4j:log4j-core:${log4jVersion}" +} diff --git a/plugins/examples/custom-processor/src/main/java/org/elasticsearch/example/customprocessor/ExampleProcessorPlugin.java b/plugins/examples/custom-processor/src/main/java/org/elasticsearch/example/customprocessor/ExampleProcessorPlugin.java new file mode 100644 index 0000000000000..d0b640ee6daec --- /dev/null +++ b/plugins/examples/custom-processor/src/main/java/org/elasticsearch/example/customprocessor/ExampleProcessorPlugin.java @@ -0,0 +1,28 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +package org.elasticsearch.example.customprocessor; + +import org.elasticsearch.ingest.Processor; +import org.elasticsearch.plugins.IngestPlugin; +import org.elasticsearch.plugins.Plugin; + +import java.util.Map; + +import static java.util.Map.entry; + +public class ExampleProcessorPlugin extends Plugin implements IngestPlugin { + + @Override + public Map getProcessors(Processor.Parameters parameters) { + return Map.ofEntries( + entry(ExampleRepeatProcessor.TYPE, new ExampleRepeatProcessor.Factory()) + ); + + } +} diff --git a/plugins/examples/custom-processor/src/main/java/org/elasticsearch/example/customprocessor/ExampleRepeatProcessor.java b/plugins/examples/custom-processor/src/main/java/org/elasticsearch/example/customprocessor/ExampleRepeatProcessor.java new file mode 100644 index 0000000000000..7ac15105bcbb7 --- /dev/null +++ b/plugins/examples/custom-processor/src/main/java/org/elasticsearch/example/customprocessor/ExampleRepeatProcessor.java @@ -0,0 +1,48 @@ +package org.elasticsearch.example.customprocessor; + +import org.elasticsearch.ingest.AbstractProcessor; +import org.elasticsearch.ingest.IngestDocument; +import org.elasticsearch.ingest.Processor; + +import java.util.Map; + +/** + * Example of adding an ingest processor with a plugin. + */ +public class ExampleRepeatProcessor extends AbstractProcessor { + public static final String TYPE = "repeat"; + public static final String FILED_TO_REPEAT = "toRepeat"; + + ExampleRepeatProcessor(String tag, String description) { + super(tag, description); + } + + @Override + public IngestDocument execute(IngestDocument document) { + Object val = document.getFieldValue(FILED_TO_REPEAT, Object.class, true); + + if (val instanceof String string) { + String repeated = string.concat(string); + document.setFieldValue(FILED_TO_REPEAT, repeated); + } + return document; + } + + @Override + public String getType() { + return TYPE; + } + + public static class Factory implements Processor.Factory { + + @Override + public ExampleRepeatProcessor create( + Map registry, + String tag, + String description, + Map config + ) { + return new ExampleRepeatProcessor(tag, description); + } + } +} diff --git a/plugins/examples/custom-processor/src/yamlRestTest/java/org/elasticsearch/example/customprocessor/ExampleProcessorClientYamlTestSuiteIT.java b/plugins/examples/custom-processor/src/yamlRestTest/java/org/elasticsearch/example/customprocessor/ExampleProcessorClientYamlTestSuiteIT.java new file mode 100644 index 0000000000000..5b8fcad4bac19 --- /dev/null +++ b/plugins/examples/custom-processor/src/yamlRestTest/java/org/elasticsearch/example/customprocessor/ExampleProcessorClientYamlTestSuiteIT.java @@ -0,0 +1,40 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ +package org.elasticsearch.example.customprocessor; + +import com.carrotsearch.randomizedtesting.annotations.Name; +import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; + +/** + * {@link ExampleProcessorClientYamlTestSuiteIT} executes the plugin's REST API integration tests. + *

+ * The tests can be executed using the command: ./gradlew :example-plugins:processor:yamlRestTest + *

+ * This class extends {@link ESClientYamlSuiteTestCase}, which takes care of parsing the YAML files + * located in the src/yamlRestTest/resources/rest-api-spec/test/ directory and validates them against the + * custom REST API definition files located in src/yamlRestTest/resources/rest-api-spec/api/. + *

+ * Once validated, {@link ESClientYamlSuiteTestCase} executes the REST tests against a single node + * integration cluster which has the plugin already installed by the Gradle build script. + *

+ */ +public class ExampleProcessorClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { + + public ExampleProcessorClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { + super(testCandidate); + } + + @ParametersFactory + public static Iterable parameters() throws Exception { + // The test executes all the test candidates by default + // see ESClientYamlSuiteTestCase.REST_TESTS_SUITE + return ESClientYamlSuiteTestCase.createParameters(); + } +} diff --git a/plugins/examples/custom-processor/src/yamlRestTest/resources/rest-api-spec/test/resthandler/10_basic.yml b/plugins/examples/custom-processor/src/yamlRestTest/resources/rest-api-spec/test/resthandler/10_basic.yml new file mode 100644 index 0000000000000..1892e7a02445b --- /dev/null +++ b/plugins/examples/custom-processor/src/yamlRestTest/resources/rest-api-spec/test/resthandler/10_basic.yml @@ -0,0 +1,13 @@ +"Custom processor is present": + - do: + ingest.put_pipeline: + id: pipeline1 + body: > + { + "processors": [ + { + "repeat" : {} + } + ] + } + - match: { acknowledged: true } diff --git a/plugins/examples/custom-processor/src/yamlRestTest/resources/rest-api-spec/test/resthandler/20_process_document.yml b/plugins/examples/custom-processor/src/yamlRestTest/resources/rest-api-spec/test/resthandler/20_process_document.yml new file mode 100644 index 0000000000000..8ff4a094b2b60 --- /dev/null +++ b/plugins/examples/custom-processor/src/yamlRestTest/resources/rest-api-spec/test/resthandler/20_process_document.yml @@ -0,0 +1,61 @@ +"Process document": + # create ingest pipeline with custom processor + - do: + ingest.put_pipeline: + id: pipeline1 + body: > + { + "processors": [ + { + "repeat" : {} + } + ] + } + - match: { acknowledged: true } + + # index a document with field to be processed + - do: + index: + id: doc1 + index: index1 + pipeline: pipeline1 + body: { toRepeat: "foo" } + - match: { result: "created" } + + # validate document is processed + - do: + get: + index: index1 + id: doc1 + - match: { _source: { toRepeat: "foofoo" } } +--- +"Does not process document without field": + # create ingest pipeline with custom processor + - do: + ingest.put_pipeline: + id: pipeline1 + body: > + { + "processors": [ + { + "repeat" : {} + } + ] + } + - match: { acknowledged: true } + + # index a document without field to be processed + - do: + index: + id: doc1 + index: index1 + pipeline: pipeline1 + body: { field1: "foo" } + - match: { result: "created" } + + # validate document is not processed + - do: + get: + index: index1 + id: doc1 + - match: { _source: { field1: "foo" } } From 2d59eac04d1d02f07193bd4a2e13d59b6c0b122e Mon Sep 17 00:00:00 2001 From: Sam Xiao Date: Wed, 28 Aug 2024 14:13:55 -0400 Subject: [PATCH 02/10] Update docs/changelog/112282.yaml --- docs/changelog/112282.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 docs/changelog/112282.yaml diff --git a/docs/changelog/112282.yaml b/docs/changelog/112282.yaml new file mode 100644 index 0000000000000..beea119b06aef --- /dev/null +++ b/docs/changelog/112282.yaml @@ -0,0 +1,6 @@ +pr: 112282 +summary: Adds example plugin for custom ingest processor +area: Ingest Node +type: enhancement +issues: + - 111539 From 2bffcc5838ee7605f60aa27093982ff1f3a21a8c Mon Sep 17 00:00:00 2001 From: Sam Xiao Date: Wed, 28 Aug 2024 14:23:01 -0400 Subject: [PATCH 03/10] Address comment 1 --- .../example/customprocessor/ExampleProcessorPlugin.java | 4 ++-- .../example/customprocessor/ExampleRepeatProcessor.java | 2 +- .../rest-api-spec/test/resthandler/20_process_document.yml | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/examples/custom-processor/src/main/java/org/elasticsearch/example/customprocessor/ExampleProcessorPlugin.java b/plugins/examples/custom-processor/src/main/java/org/elasticsearch/example/customprocessor/ExampleProcessorPlugin.java index d0b640ee6daec..fd94464d77ebf 100644 --- a/plugins/examples/custom-processor/src/main/java/org/elasticsearch/example/customprocessor/ExampleProcessorPlugin.java +++ b/plugins/examples/custom-processor/src/main/java/org/elasticsearch/example/customprocessor/ExampleProcessorPlugin.java @@ -20,8 +20,8 @@ public class ExampleProcessorPlugin extends Plugin implements IngestPlugin { @Override public Map getProcessors(Processor.Parameters parameters) { - return Map.ofEntries( - entry(ExampleRepeatProcessor.TYPE, new ExampleRepeatProcessor.Factory()) + return Map.of( + ExampleRepeatProcessor.TYPE, new ExampleRepeatProcessor.Factory() ); } diff --git a/plugins/examples/custom-processor/src/main/java/org/elasticsearch/example/customprocessor/ExampleRepeatProcessor.java b/plugins/examples/custom-processor/src/main/java/org/elasticsearch/example/customprocessor/ExampleRepeatProcessor.java index 7ac15105bcbb7..e25eec95be824 100644 --- a/plugins/examples/custom-processor/src/main/java/org/elasticsearch/example/customprocessor/ExampleRepeatProcessor.java +++ b/plugins/examples/custom-processor/src/main/java/org/elasticsearch/example/customprocessor/ExampleRepeatProcessor.java @@ -11,7 +11,7 @@ */ public class ExampleRepeatProcessor extends AbstractProcessor { public static final String TYPE = "repeat"; - public static final String FILED_TO_REPEAT = "toRepeat"; + public static final String FILED_TO_REPEAT = "to_repeat"; ExampleRepeatProcessor(String tag, String description) { super(tag, description); diff --git a/plugins/examples/custom-processor/src/yamlRestTest/resources/rest-api-spec/test/resthandler/20_process_document.yml b/plugins/examples/custom-processor/src/yamlRestTest/resources/rest-api-spec/test/resthandler/20_process_document.yml index 8ff4a094b2b60..d7c9b0ba03a99 100644 --- a/plugins/examples/custom-processor/src/yamlRestTest/resources/rest-api-spec/test/resthandler/20_process_document.yml +++ b/plugins/examples/custom-processor/src/yamlRestTest/resources/rest-api-spec/test/resthandler/20_process_document.yml @@ -19,7 +19,7 @@ id: doc1 index: index1 pipeline: pipeline1 - body: { toRepeat: "foo" } + body: { to_repeat: "foo" } - match: { result: "created" } # validate document is processed @@ -27,7 +27,7 @@ get: index: index1 id: doc1 - - match: { _source: { toRepeat: "foofoo" } } + - match: { _source: { to_repeat: "foofoo" } } --- "Does not process document without field": # create ingest pipeline with custom processor From 3b72caded6e98b3f9f6b1d6ed7342f1edeec7948 Mon Sep 17 00:00:00 2001 From: Sam Xiao Date: Tue, 3 Sep 2024 17:15:00 -0400 Subject: [PATCH 04/10] Fix name --- .../example/customprocessor/ExampleRepeatProcessor.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/examples/custom-processor/src/main/java/org/elasticsearch/example/customprocessor/ExampleRepeatProcessor.java b/plugins/examples/custom-processor/src/main/java/org/elasticsearch/example/customprocessor/ExampleRepeatProcessor.java index e25eec95be824..726e5874a8303 100644 --- a/plugins/examples/custom-processor/src/main/java/org/elasticsearch/example/customprocessor/ExampleRepeatProcessor.java +++ b/plugins/examples/custom-processor/src/main/java/org/elasticsearch/example/customprocessor/ExampleRepeatProcessor.java @@ -11,7 +11,7 @@ */ public class ExampleRepeatProcessor extends AbstractProcessor { public static final String TYPE = "repeat"; - public static final String FILED_TO_REPEAT = "to_repeat"; + public static final String FIELD_TO_REPEAT = "to_repeat"; ExampleRepeatProcessor(String tag, String description) { super(tag, description); @@ -19,11 +19,11 @@ public class ExampleRepeatProcessor extends AbstractProcessor { @Override public IngestDocument execute(IngestDocument document) { - Object val = document.getFieldValue(FILED_TO_REPEAT, Object.class, true); + Object val = document.getFieldValue(FIELD_TO_REPEAT, Object.class, true); if (val instanceof String string) { String repeated = string.concat(string); - document.setFieldValue(FILED_TO_REPEAT, repeated); + document.setFieldValue(FIELD_TO_REPEAT, repeated); } return document; } From 16d4bec6483b1c0c9c93df6f85b7213a3ebd52b9 Mon Sep 17 00:00:00 2001 From: Sam Xiao Date: Wed, 4 Sep 2024 15:00:38 -0400 Subject: [PATCH 05/10] Add custom field name --- .../customprocessor/ExampleRepeatProcessor.java | 14 +++++++++----- .../rest-api-spec/test/resthandler/10_basic.yml | 4 +++- .../test/resthandler/20_process_document.yml | 8 ++++++-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/plugins/examples/custom-processor/src/main/java/org/elasticsearch/example/customprocessor/ExampleRepeatProcessor.java b/plugins/examples/custom-processor/src/main/java/org/elasticsearch/example/customprocessor/ExampleRepeatProcessor.java index 726e5874a8303..3938e2b9ce832 100644 --- a/plugins/examples/custom-processor/src/main/java/org/elasticsearch/example/customprocessor/ExampleRepeatProcessor.java +++ b/plugins/examples/custom-processor/src/main/java/org/elasticsearch/example/customprocessor/ExampleRepeatProcessor.java @@ -1,6 +1,7 @@ package org.elasticsearch.example.customprocessor; import org.elasticsearch.ingest.AbstractProcessor; +import org.elasticsearch.ingest.ConfigurationUtils; import org.elasticsearch.ingest.IngestDocument; import org.elasticsearch.ingest.Processor; @@ -11,19 +12,21 @@ */ public class ExampleRepeatProcessor extends AbstractProcessor { public static final String TYPE = "repeat"; - public static final String FIELD_TO_REPEAT = "to_repeat"; - ExampleRepeatProcessor(String tag, String description) { + private final String field; + + ExampleRepeatProcessor(String tag, String description, String field) { super(tag, description); + this.field = field; } @Override public IngestDocument execute(IngestDocument document) { - Object val = document.getFieldValue(FIELD_TO_REPEAT, Object.class, true); + Object val = document.getFieldValue(field, Object.class, true); if (val instanceof String string) { String repeated = string.concat(string); - document.setFieldValue(FIELD_TO_REPEAT, repeated); + document.setFieldValue(field, repeated); } return document; } @@ -42,7 +45,8 @@ public ExampleRepeatProcessor create( String description, Map config ) { - return new ExampleRepeatProcessor(tag, description); + String field = ConfigurationUtils.readStringProperty(TYPE, tag, config, "field"); + return new ExampleRepeatProcessor(tag, description, field); } } } diff --git a/plugins/examples/custom-processor/src/yamlRestTest/resources/rest-api-spec/test/resthandler/10_basic.yml b/plugins/examples/custom-processor/src/yamlRestTest/resources/rest-api-spec/test/resthandler/10_basic.yml index 1892e7a02445b..40f5835fe9760 100644 --- a/plugins/examples/custom-processor/src/yamlRestTest/resources/rest-api-spec/test/resthandler/10_basic.yml +++ b/plugins/examples/custom-processor/src/yamlRestTest/resources/rest-api-spec/test/resthandler/10_basic.yml @@ -6,7 +6,9 @@ { "processors": [ { - "repeat" : {} + "repeat" : { + "field": "test" + } } ] } diff --git a/plugins/examples/custom-processor/src/yamlRestTest/resources/rest-api-spec/test/resthandler/20_process_document.yml b/plugins/examples/custom-processor/src/yamlRestTest/resources/rest-api-spec/test/resthandler/20_process_document.yml index d7c9b0ba03a99..be1520fb283bb 100644 --- a/plugins/examples/custom-processor/src/yamlRestTest/resources/rest-api-spec/test/resthandler/20_process_document.yml +++ b/plugins/examples/custom-processor/src/yamlRestTest/resources/rest-api-spec/test/resthandler/20_process_document.yml @@ -7,7 +7,9 @@ { "processors": [ { - "repeat" : {} + "repeat" : { + "field": "to_repeat" + } } ] } @@ -38,7 +40,9 @@ { "processors": [ { - "repeat" : {} + "repeat" : { + "field": "to_repeat" + } } ] } From e24084e7439a1d8ec151c91e6e7d1027869d9334 Mon Sep 17 00:00:00 2001 From: Sam Xiao Date: Thu, 5 Sep 2024 11:02:21 -0400 Subject: [PATCH 06/10] Add yaml setup/teardown, address comment --- .../ExampleRepeatProcessor.java | 3 +- .../test/resthandler/20_process_document.yml | 32 ++++++++----------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/plugins/examples/custom-processor/src/main/java/org/elasticsearch/example/customprocessor/ExampleRepeatProcessor.java b/plugins/examples/custom-processor/src/main/java/org/elasticsearch/example/customprocessor/ExampleRepeatProcessor.java index 3938e2b9ce832..f0f942459281a 100644 --- a/plugins/examples/custom-processor/src/main/java/org/elasticsearch/example/customprocessor/ExampleRepeatProcessor.java +++ b/plugins/examples/custom-processor/src/main/java/org/elasticsearch/example/customprocessor/ExampleRepeatProcessor.java @@ -12,6 +12,7 @@ */ public class ExampleRepeatProcessor extends AbstractProcessor { public static final String TYPE = "repeat"; + public static final String FIELD_KEY_NAME = "field"; private final String field; @@ -45,7 +46,7 @@ public ExampleRepeatProcessor create( String description, Map config ) { - String field = ConfigurationUtils.readStringProperty(TYPE, tag, config, "field"); + String field = ConfigurationUtils.readStringProperty(TYPE, tag, config, FIELD_KEY_NAME); return new ExampleRepeatProcessor(tag, description, field); } } diff --git a/plugins/examples/custom-processor/src/yamlRestTest/resources/rest-api-spec/test/resthandler/20_process_document.yml b/plugins/examples/custom-processor/src/yamlRestTest/resources/rest-api-spec/test/resthandler/20_process_document.yml index be1520fb283bb..7e8bc2e0a2d78 100644 --- a/plugins/examples/custom-processor/src/yamlRestTest/resources/rest-api-spec/test/resthandler/20_process_document.yml +++ b/plugins/examples/custom-processor/src/yamlRestTest/resources/rest-api-spec/test/resthandler/20_process_document.yml @@ -1,5 +1,4 @@ -"Process document": - # create ingest pipeline with custom processor +setup: - do: ingest.put_pipeline: id: pipeline1 @@ -13,8 +12,19 @@ } ] } - - match: { acknowledged: true } +--- +teardown: + - do: + ingest.delete_pipeline: + id: pipeline1 + ignore: 404 + - do: + indices.delete: + index: index1 + ignore: 404 +--- +"Process document": # index a document with field to be processed - do: index: @@ -32,22 +42,6 @@ - match: { _source: { to_repeat: "foofoo" } } --- "Does not process document without field": - # create ingest pipeline with custom processor - - do: - ingest.put_pipeline: - id: pipeline1 - body: > - { - "processors": [ - { - "repeat" : { - "field": "to_repeat" - } - } - ] - } - - match: { acknowledged: true } - # index a document without field to be processed - do: index: From c4d019e15cabb58f36c0b268e8f231a002dfb89e Mon Sep 17 00:00:00 2001 From: Joe Gallo Date: Thu, 5 Sep 2024 12:52:44 -0400 Subject: [PATCH 07/10] Drop an unused import --- .../example/customprocessor/ExampleProcessorPlugin.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/examples/custom-processor/src/main/java/org/elasticsearch/example/customprocessor/ExampleProcessorPlugin.java b/plugins/examples/custom-processor/src/main/java/org/elasticsearch/example/customprocessor/ExampleProcessorPlugin.java index fd94464d77ebf..74654ecfd8aab 100644 --- a/plugins/examples/custom-processor/src/main/java/org/elasticsearch/example/customprocessor/ExampleProcessorPlugin.java +++ b/plugins/examples/custom-processor/src/main/java/org/elasticsearch/example/customprocessor/ExampleProcessorPlugin.java @@ -14,8 +14,6 @@ import java.util.Map; -import static java.util.Map.entry; - public class ExampleProcessorPlugin extends Plugin implements IngestPlugin { @Override From 2a6e9ac8a1f62168c50f9a0c90c2f4790ff1d81c Mon Sep 17 00:00:00 2001 From: Joe Gallo Date: Thu, 5 Sep 2024 12:52:55 -0400 Subject: [PATCH 08/10] Whitespace --- .../example/customprocessor/ExampleProcessorPlugin.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/plugins/examples/custom-processor/src/main/java/org/elasticsearch/example/customprocessor/ExampleProcessorPlugin.java b/plugins/examples/custom-processor/src/main/java/org/elasticsearch/example/customprocessor/ExampleProcessorPlugin.java index 74654ecfd8aab..1ba145a92ca7d 100644 --- a/plugins/examples/custom-processor/src/main/java/org/elasticsearch/example/customprocessor/ExampleProcessorPlugin.java +++ b/plugins/examples/custom-processor/src/main/java/org/elasticsearch/example/customprocessor/ExampleProcessorPlugin.java @@ -18,9 +18,6 @@ public class ExampleProcessorPlugin extends Plugin implements IngestPlugin { @Override public Map getProcessors(Processor.Parameters parameters) { - return Map.of( - ExampleRepeatProcessor.TYPE, new ExampleRepeatProcessor.Factory() - ); - + return Map.of(ExampleRepeatProcessor.TYPE, new ExampleRepeatProcessor.Factory()); } } From f701626b386d054ec846be1d2142d6bf22d38b21 Mon Sep 17 00:00:00 2001 From: Joe Gallo Date: Thu, 5 Sep 2024 12:53:40 -0400 Subject: [PATCH 09/10] Fix a typo --- docs/plugins/development/creating-classic-plugins.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/plugins/development/creating-classic-plugins.asciidoc b/docs/plugins/development/creating-classic-plugins.asciidoc index 04a646d7262b4..cc03ad51275fa 100644 --- a/docs/plugins/development/creating-classic-plugins.asciidoc +++ b/docs/plugins/development/creating-classic-plugins.asciidoc @@ -32,7 +32,7 @@ for the plugin. If you need other resources, package them into a resources JAR. The {es} repository contains {es-repo}tree/main/plugins/examples[examples of plugins]. Some of these include: * a plugin with {es-repo}tree/main/plugins/examples/custom-settings[custom settings] -* a plugin with {es-repo}tree/main/plugins/examples/custom-processor[custom ingest processor] +* a plugin with a {es-repo}tree/main/plugins/examples/custom-processor[custom ingest processor] * adding {es-repo}tree/main/plugins/examples/rest-handler[custom rest endpoints] * adding a {es-repo}tree/main/plugins/examples/rescore[custom rescorer] * a script {es-repo}tree/main/plugins/examples/script-expert-scoring[implemented in Java] From 727790f5bf8eab4d73559c27f97da2f18b7703df Mon Sep 17 00:00:00 2001 From: Sam Xiao Date: Thu, 5 Sep 2024 15:45:00 -0400 Subject: [PATCH 10/10] Fix comment and folder name --- .../customprocessor/ExampleProcessorClientYamlTestSuiteIT.java | 2 +- .../test/{resthandler => customprocessor}/10_basic.yml | 0 .../{resthandler => customprocessor}/20_process_document.yml | 0 3 files changed, 1 insertion(+), 1 deletion(-) rename plugins/examples/custom-processor/src/yamlRestTest/resources/rest-api-spec/test/{resthandler => customprocessor}/10_basic.yml (100%) rename plugins/examples/custom-processor/src/yamlRestTest/resources/rest-api-spec/test/{resthandler => customprocessor}/20_process_document.yml (100%) diff --git a/plugins/examples/custom-processor/src/yamlRestTest/java/org/elasticsearch/example/customprocessor/ExampleProcessorClientYamlTestSuiteIT.java b/plugins/examples/custom-processor/src/yamlRestTest/java/org/elasticsearch/example/customprocessor/ExampleProcessorClientYamlTestSuiteIT.java index 5b8fcad4bac19..ac08df358fe5e 100644 --- a/plugins/examples/custom-processor/src/yamlRestTest/java/org/elasticsearch/example/customprocessor/ExampleProcessorClientYamlTestSuiteIT.java +++ b/plugins/examples/custom-processor/src/yamlRestTest/java/org/elasticsearch/example/customprocessor/ExampleProcessorClientYamlTestSuiteIT.java @@ -15,7 +15,7 @@ /** * {@link ExampleProcessorClientYamlTestSuiteIT} executes the plugin's REST API integration tests. *

- * The tests can be executed using the command: ./gradlew :example-plugins:processor:yamlRestTest + * The tests can be executed using the command: ./gradlew :custom-processor:yamlRestTest *

* This class extends {@link ESClientYamlSuiteTestCase}, which takes care of parsing the YAML files * located in the src/yamlRestTest/resources/rest-api-spec/test/ directory and validates them against the diff --git a/plugins/examples/custom-processor/src/yamlRestTest/resources/rest-api-spec/test/resthandler/10_basic.yml b/plugins/examples/custom-processor/src/yamlRestTest/resources/rest-api-spec/test/customprocessor/10_basic.yml similarity index 100% rename from plugins/examples/custom-processor/src/yamlRestTest/resources/rest-api-spec/test/resthandler/10_basic.yml rename to plugins/examples/custom-processor/src/yamlRestTest/resources/rest-api-spec/test/customprocessor/10_basic.yml diff --git a/plugins/examples/custom-processor/src/yamlRestTest/resources/rest-api-spec/test/resthandler/20_process_document.yml b/plugins/examples/custom-processor/src/yamlRestTest/resources/rest-api-spec/test/customprocessor/20_process_document.yml similarity index 100% rename from plugins/examples/custom-processor/src/yamlRestTest/resources/rest-api-spec/test/resthandler/20_process_document.yml rename to plugins/examples/custom-processor/src/yamlRestTest/resources/rest-api-spec/test/customprocessor/20_process_document.yml