From 45f48ac12674f66b9eac4afa8abfc438686cc06a Mon Sep 17 00:00:00 2001 From: Tal Levy Date: Mon, 30 Nov 2015 18:05:17 -0800 Subject: [PATCH] update all processors to only operate on one field at a time when possible --- docs/plugins/ingest.asciidoc | 55 ++-- .../processor/AbstractStringProcessor.java | 26 +- .../ingest/processor/ConfigurationUtils.java | 11 + .../processor/convert/ConvertProcessor.java | 60 ++-- .../ingest/processor/gsub/GsubExpression.java | 70 ----- .../ingest/processor/gsub/GsubProcessor.java | 63 ++-- .../ingest/processor/join/JoinProcessor.java | 39 ++- .../lowercase/LowercaseProcessor.java | 8 +- .../processor/remove/RemoveProcessor.java | 21 +- .../processor/rename/RenameProcessor.java | 54 ++-- .../ingest/processor/set/SetProcessor.java | 26 +- .../processor/split/SplitProcessor.java | 30 +- .../ingest/processor/trim/TrimProcessor.java | 8 +- .../uppercase/UppercaseProcessor.java | 8 +- .../AbstractStringProcessorTestCase.java | 23 +- .../convert/ConvertProcessorFactoryTests.java | 48 ++- .../convert/ConvertProcessorTests.java | 291 +++++++----------- .../gsub/GsubProcessorFactoryTests.java | 59 +--- .../processor/gsub/GsubProcessorTests.java | 22 +- .../join/JoinProcessorFactoryTests.java | 27 +- .../processor/join/JoinProcessorTests.java | 77 ++--- .../LowercaseProcessorFactoryTests.java | 9 +- .../lowercase/LowercaseProcessorTests.java | 4 +- .../remove/RemoveProcessorFactoryTests.java | 9 +- .../remove/RemoveProcessorTests.java | 14 +- .../rename/RenameProcessorFactoryTests.java | 24 +- .../rename/RenameProcessorTests.java | 41 +-- .../set/SetProcessorFactoryTests.java | 37 ++- .../processor/set/SetProcessorTests.java | 37 +-- .../split/SplitProcessorFactoryTests.java | 24 +- .../processor/split/SplitProcessorTests.java | 21 +- .../trim/TrimProcessorFactoryTests.java | 9 +- .../processor/trim/TrimProcessorTests.java | 6 +- .../UppercaseProcessorFactoryTests.java | 9 +- .../uppercase/UppercaseProcessorTests.java | 4 +- .../rest-api-spec/test/ingest/20_crud.yaml | 5 +- .../rest-api-spec/test/ingest/60_mutate.yaml | 51 +-- .../test/ingest/80_simulate.yaml | 29 +- 38 files changed, 582 insertions(+), 777 deletions(-) delete mode 100644 plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/gsub/GsubExpression.java diff --git a/docs/plugins/ingest.asciidoc b/docs/plugins/ingest.asciidoc index 46d57fbe994..0ae37433bae 100644 --- a/docs/plugins/ingest.asciidoc +++ b/docs/plugins/ingest.asciidoc @@ -4,52 +4,46 @@ === Processors ==== Set processor -Sets one or more fields and associates them with the specified values. If a field already exists, +Sets one field and associates it with the specified value. If a field already exists, its value will be replaced with the provided one. [source,js] -------------------------------------------------- { "set": { - "fields": { - "field": 582.1 - } + "field1": 582.1 } } -------------------------------------------------- ==== Remove processor -Removes one or more existing fields. If a field doesn't exist, nothing will happen. +Removes an existing field. If a field doesn't exist, nothing will happen. [source,js] -------------------------------------------------- { "remove": { - "fields": [ - "field1","field2" - ] + "field": "foo" } } -------------------------------------------------- ==== Rename processor -Renames one or more existing fields. If a field doesn't exist, an exception will be thrown. Also, the new field +Renames an existing fields. If a field doesn't exist, an exception will be thrown. Also, the new field name must not exist. [source,js] -------------------------------------------------- { "rename": { - "fields": { - "field1": "field2" - } + "field": "foo" } } -------------------------------------------------- ==== Convert processor -Converts one or more field value to a different type, like turning a string to an integer. +Converts an existing field's value to a different type, like turning a string to an integer. If the field value is an array, all members will be converted. The supported types include: `integer`, `float`, `string`, and `boolean`. @@ -61,10 +55,7 @@ false if its string value is equal to `false` (ignore case) and it will throw ex -------------------------------------------------- { "convert": { - "fields": { - "field1": "integer", - "field2": "float" - } + "foo": "integer" } } -------------------------------------------------- @@ -73,8 +64,7 @@ false if its string value is equal to `false` (ignore case) and it will throw ex Converts a string field by applying a regular expression and a replacement. If the field is not a string, the processor will throw an exception. -This configuration takes an `expression` array consisting of objects. Each object -holds three elements: `field` for the field name, `pattern` for the +This configuration takes a `field` for the field name, `pattern` for the pattern to be replaced, and `replacement` for the string to replace the matching patterns with. @@ -82,13 +72,9 @@ pattern to be replaced, and `replacement` for the string to replace the matching -------------------------------------------------- { "gsub": { - "expressions": [ - { - "field": "field1", - "pattern": "\.", - "replacement": "-" - } - ] + "field": "field1", + "pattern": "\.", + "replacement": "-" } } -------------------------------------------------- @@ -101,9 +87,8 @@ Throws error when the field is not an array. -------------------------------------------------- { "join": { - "fields": { - "joined_array_field": "other_array_field" - } + "field": "joined_array_field", + "separator": "-" } } -------------------------------------------------- @@ -115,9 +100,7 @@ Split a field to an array using a separator character. Only works on string fiel -------------------------------------------------- { "split": { - "fields": { - "message": "," - } + "field": "," } } -------------------------------------------------- @@ -129,7 +112,7 @@ Converts a string to its lowercase equivalent. -------------------------------------------------- { "lowercase": { - "fields": ["foo", "bar"] + "field": "foo" } } -------------------------------------------------- @@ -141,7 +124,7 @@ Converts a string to its uppercase equivalent. -------------------------------------------------- { "uppercase": { - "fields": ["foo", "bar"] + "field": "foo" } } -------------------------------------------------- @@ -153,7 +136,7 @@ Trims whitespace from field. NOTE: this only works on leading and trailing white -------------------------------------------------- { "trim": { - "fields": ["foo", "bar"] + "field": "foo" } } -------------------------------------------------- @@ -538,4 +521,4 @@ The delete pipeline api deletes pipelines by id. -------------------------------------------------- DELETE _ingest/pipeline/my-pipeline-id -------------------------------------------------- -// AUTOSENSE \ No newline at end of file +// AUTOSENSE diff --git a/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/AbstractStringProcessor.java b/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/AbstractStringProcessor.java index 21d2c6c7d14..475ace15552 100644 --- a/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/AbstractStringProcessor.java +++ b/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/AbstractStringProcessor.java @@ -32,25 +32,23 @@ import java.util.Map; */ public abstract class AbstractStringProcessor implements Processor { - private final Collection fields; + private final String field; - protected AbstractStringProcessor(Collection fields) { - this.fields = fields; + protected AbstractStringProcessor(String field) { + this.field = field; } - public Collection getFields() { - return fields; + public String getField() { + return field; } @Override public final void execute(IngestDocument document) { - for(String field : fields) { - String val = document.getFieldValue(field, String.class); - if (val == null) { - throw new IllegalArgumentException("field [" + field + "] is null, cannot process it."); - } - document.setFieldValue(field, process(val)); + String val = document.getFieldValue(field, String.class); + if (val == null) { + throw new IllegalArgumentException("field [" + field + "] is null, cannot process it."); } + document.setFieldValue(field, process(val)); } protected abstract String process(String value); @@ -58,10 +56,10 @@ public abstract class AbstractStringProcessor implements Processor { public static abstract class Factory implements Processor.Factory { @Override public T create(Map config) throws Exception { - List fields = ConfigurationUtils.readList(config, "fields"); - return newProcessor(Collections.unmodifiableList(fields)); + String field = ConfigurationUtils.readStringProperty(config, "field"); + return newProcessor(field); } - protected abstract T newProcessor(Collection fields); + protected abstract T newProcessor(String field); } } diff --git a/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/ConfigurationUtils.java b/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/ConfigurationUtils.java index af001decc08..7ba737eb56e 100644 --- a/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/ConfigurationUtils.java +++ b/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/ConfigurationUtils.java @@ -149,4 +149,15 @@ public final class ConfigurationUtils { throw new IllegalArgumentException("property [" + propertyName + "] isn't a map, but of type [" + value.getClass().getName() + "]"); } } + + /** + * Returns and removes the specified property as an {@link Object} from the specified configuration map. + */ + public static Object readObject(Map configuration, String propertyName) { + Object value = configuration.remove(propertyName); + if (value == null) { + throw new IllegalArgumentException("required property [" + propertyName + "] is missing"); + } + return value; + } } diff --git a/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/convert/ConvertProcessor.java b/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/convert/ConvertProcessor.java index d86fea0485f..0944305c8b6 100644 --- a/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/convert/ConvertProcessor.java +++ b/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/convert/ConvertProcessor.java @@ -87,38 +87,41 @@ public class ConvertProcessor implements Processor { public static final String TYPE = "convert"; - private final Map fields; + private final String field; + private final Type convertType; - ConvertProcessor(Map fields) { - this.fields = fields; + ConvertProcessor(String field, Type convertType) { + this.field = field; + this.convertType = convertType; } - Map getFields() { - return fields; + String getField() { + return field; + } + + Type getConvertType() { + return convertType; } @Override public void execute(IngestDocument document) { - for(Map.Entry entry : fields.entrySet()) { - Type type = entry.getValue(); - Object oldValue = document.getFieldValue(entry.getKey(), Object.class); - Object newValue; - if (oldValue == null) { - throw new IllegalArgumentException("Field [" + entry.getKey() + "] is null, cannot be converted to type [" + type + "]"); - } - - if (oldValue instanceof List) { - List list = (List) oldValue; - List newList = new ArrayList<>(); - for (Object value : list) { - newList.add(type.convert(value)); - } - newValue = newList; - } else { - newValue = type.convert(oldValue); - } - document.setFieldValue(entry.getKey(), newValue); + Object oldValue = document.getFieldValue(field, Object.class); + Object newValue; + if (oldValue == null) { + throw new IllegalArgumentException("Field [" + field + "] is null, cannot be converted to type [" + convertType + "]"); } + + if (oldValue instanceof List) { + List list = (List) oldValue; + List newList = new ArrayList<>(); + for (Object value : list) { + newList.add(convertType.convert(value)); + } + newValue = newList; + } else { + newValue = convertType.convert(oldValue); + } + document.setFieldValue(field, newValue); } @Override @@ -129,12 +132,9 @@ public class ConvertProcessor implements Processor { public static class Factory implements Processor.Factory { @Override public ConvertProcessor create(Map config) throws Exception { - Map fields = ConfigurationUtils.readMap(config, "fields"); - Map convertFields = new HashMap<>(); - for (Map.Entry entry : fields.entrySet()) { - convertFields.put(entry.getKey(), Type.fromString(entry.getValue())); - } - return new ConvertProcessor(Collections.unmodifiableMap(convertFields)); + String field = ConfigurationUtils.readStringProperty(config, "field"); + Type convertType = Type.fromString(ConfigurationUtils.readStringProperty(config, "type")); + return new ConvertProcessor(field, convertType); } } } diff --git a/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/gsub/GsubExpression.java b/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/gsub/GsubExpression.java deleted file mode 100644 index 54d55a0add0..00000000000 --- a/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/gsub/GsubExpression.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.ingest.processor.gsub; - -import java.util.Objects; -import java.util.regex.Pattern; - -/** - * Represents a gsub expression containing the field name, the pattern to look for and its string replacement. - */ -public class GsubExpression { - - private final String fieldName; - private final Pattern pattern; - private final String replacement; - - public GsubExpression(String fieldName, Pattern pattern, String replacement) { - this.fieldName = Objects.requireNonNull(fieldName); - this.pattern = Objects.requireNonNull(pattern); - this.replacement = Objects.requireNonNull(replacement); - } - - public String getFieldName() { - return fieldName; - } - - public Pattern getPattern() { - return pattern; - } - - public String getReplacement() { - return replacement; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - GsubExpression that = (GsubExpression) o; - return Objects.equals(fieldName, that.fieldName) && - Objects.equals(pattern.pattern(), that.pattern.pattern()) && - Objects.equals(replacement, that.replacement); - } - - @Override - public int hashCode() { - return Objects.hash(fieldName, pattern, replacement); - } -} diff --git a/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/gsub/GsubProcessor.java b/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/gsub/GsubProcessor.java index 8eb6c7dbc89..e15f99d9fed 100644 --- a/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/gsub/GsubProcessor.java +++ b/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/gsub/GsubProcessor.java @@ -23,8 +23,6 @@ import org.elasticsearch.ingest.IngestDocument; import org.elasticsearch.ingest.processor.ConfigurationUtils; import org.elasticsearch.ingest.processor.Processor; -import java.util.ArrayList; -import java.util.List; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -37,27 +35,38 @@ public class GsubProcessor implements Processor { public static final String TYPE = "gsub"; - private final List gsubExpressions; + private final String field; + private final Pattern pattern; + private final String replacement; - GsubProcessor(List gsubExpressions) { - this.gsubExpressions = gsubExpressions; + GsubProcessor(String field, Pattern pattern, String replacement) { + this.field = field; + this.pattern = pattern; + this.replacement = replacement; } - List getGsubExpressions() { - return gsubExpressions; + String getField() { + return field; } + Pattern getPattern() { + return pattern; + } + + String getReplacement() { + return replacement; + } + + @Override public void execute(IngestDocument document) { - for (GsubExpression gsubExpression : gsubExpressions) { - String oldVal = document.getFieldValue(gsubExpression.getFieldName(), String.class); - if (oldVal == null) { - throw new IllegalArgumentException("field [" + gsubExpression.getFieldName() + "] is null, cannot match pattern."); - } - Matcher matcher = gsubExpression.getPattern().matcher(oldVal); - String newVal = matcher.replaceAll(gsubExpression.getReplacement()); - document.setFieldValue(gsubExpression.getFieldName(), newVal); + String oldVal = document.getFieldValue(field, String.class); + if (oldVal == null) { + throw new IllegalArgumentException("field [" + field + "] is null, cannot match pattern."); } + Matcher matcher = pattern.matcher(oldVal); + String newVal = matcher.replaceAll(replacement); + document.setFieldValue(field, newVal); } @Override @@ -68,25 +77,11 @@ public class GsubProcessor implements Processor { public static class Factory implements Processor.Factory { @Override public GsubProcessor create(Map config) throws Exception { - List> gsubConfig = ConfigurationUtils.readList(config, "expressions"); - List gsubExpressions = new ArrayList<>(); - for (Map stringObjectMap : gsubConfig) { - String field = stringObjectMap.get("field"); - if (field == null) { - throw new IllegalArgumentException("no [field] specified for gsub expression"); - } - String pattern = stringObjectMap.get("pattern"); - if (pattern == null) { - throw new IllegalArgumentException("no [pattern] specified for gsub expression"); - } - String replacement = stringObjectMap.get("replacement"); - if (replacement == null) { - throw new IllegalArgumentException("no [replacement] specified for gsub expression"); - } - Pattern searchPattern = Pattern.compile(pattern); - gsubExpressions.add(new GsubExpression(field, searchPattern, replacement)); - } - return new GsubProcessor(gsubExpressions); + String field = ConfigurationUtils.readStringProperty(config, "field"); + String pattern = ConfigurationUtils.readStringProperty(config, "pattern"); + String replacement = ConfigurationUtils.readStringProperty(config, "replacement"); + Pattern searchPattern = Pattern.compile(pattern); + return new GsubProcessor(field, searchPattern, replacement); } } } diff --git a/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/join/JoinProcessor.java b/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/join/JoinProcessor.java index 40016b489fd..85be2316777 100644 --- a/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/join/JoinProcessor.java +++ b/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/join/JoinProcessor.java @@ -23,7 +23,7 @@ import org.elasticsearch.ingest.IngestDocument; import org.elasticsearch.ingest.processor.ConfigurationUtils; import org.elasticsearch.ingest.processor.Processor; -import java.util.Collections; +import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -36,28 +36,32 @@ public class JoinProcessor implements Processor { public static final String TYPE = "join"; - private final Map fields; + private final String field; + private final String separator; - JoinProcessor(Map fields) { - this.fields = fields; + JoinProcessor(String field, String separator) { + this.field = field; + this.separator = separator; } - Map getFields() { - return fields; + String getField() { + return field; + } + + String getSeparator() { + return separator; } @Override public void execute(IngestDocument document) { - for(Map.Entry entry : fields.entrySet()) { - List list = document.getFieldValue(entry.getKey(), List.class); - if (list == null) { - throw new IllegalArgumentException("field [" + entry.getKey() + "] is null, cannot join."); - } - String joined = list.stream() - .map(Object::toString) - .collect(Collectors.joining(entry.getValue())); - document.setFieldValue(entry.getKey(), joined); + List list = document.getFieldValue(field, List.class); + if (list == null) { + throw new IllegalArgumentException("field [" + field + "] is null, cannot join."); } + String joined = list.stream() + .map(Object::toString) + .collect(Collectors.joining(separator)); + document.setFieldValue(field, joined); } @Override @@ -68,8 +72,9 @@ public class JoinProcessor implements Processor { public static class Factory implements Processor.Factory { @Override public JoinProcessor create(Map config) throws Exception { - Map fields = ConfigurationUtils.readMap(config, "fields"); - return new JoinProcessor(Collections.unmodifiableMap(fields)); + String field = ConfigurationUtils.readStringProperty(config, "field"); + String separator = ConfigurationUtils.readStringProperty(config, "separator"); + return new JoinProcessor(field, separator); } } } diff --git a/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/lowercase/LowercaseProcessor.java b/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/lowercase/LowercaseProcessor.java index 751a566d10a..6bff6223053 100644 --- a/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/lowercase/LowercaseProcessor.java +++ b/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/lowercase/LowercaseProcessor.java @@ -33,8 +33,8 @@ public class LowercaseProcessor extends AbstractStringProcessor { public static final String TYPE = "lowercase"; - LowercaseProcessor(Collection fields) { - super(fields); + LowercaseProcessor(String field) { + super(field); } @Override @@ -49,8 +49,8 @@ public class LowercaseProcessor extends AbstractStringProcessor { public static class Factory extends AbstractStringProcessor.Factory { @Override - protected LowercaseProcessor newProcessor(Collection fields) { - return new LowercaseProcessor(fields); + protected LowercaseProcessor newProcessor(String field) { + return new LowercaseProcessor(field); } } } diff --git a/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/remove/RemoveProcessor.java b/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/remove/RemoveProcessor.java index f04c407b14a..80cd017ef78 100644 --- a/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/remove/RemoveProcessor.java +++ b/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/remove/RemoveProcessor.java @@ -23,9 +23,6 @@ import org.elasticsearch.ingest.IngestDocument; import org.elasticsearch.ingest.processor.ConfigurationUtils; import org.elasticsearch.ingest.processor.Processor; -import java.util.Collection; -import java.util.Collections; -import java.util.List; import java.util.Map; /** @@ -35,21 +32,19 @@ public class RemoveProcessor implements Processor { public static final String TYPE = "remove"; - private final Collection fields; + private final String field; - RemoveProcessor(Collection fields) { - this.fields = fields; + RemoveProcessor(String field) { + this.field = field; } - Collection getFields() { - return fields; + String getField() { + return field; } @Override public void execute(IngestDocument document) { - for(String field : fields) { - document.removeField(field); - } + document.removeField(field); } @Override @@ -60,8 +55,8 @@ public class RemoveProcessor implements Processor { public static class Factory implements Processor.Factory { @Override public RemoveProcessor create(Map config) throws Exception { - List fields = ConfigurationUtils.readList(config, "fields"); - return new RemoveProcessor(Collections.unmodifiableList(fields)); + String field = ConfigurationUtils.readStringProperty(config, "field"); + return new RemoveProcessor(field); } } } diff --git a/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/rename/RenameProcessor.java b/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/rename/RenameProcessor.java index 25dde43ea93..7e894e53893 100644 --- a/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/rename/RenameProcessor.java +++ b/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/rename/RenameProcessor.java @@ -23,6 +23,7 @@ import org.elasticsearch.ingest.IngestDocument; import org.elasticsearch.ingest.processor.ConfigurationUtils; import org.elasticsearch.ingest.processor.Processor; +import java.util.Arrays; import java.util.Collections; import java.util.Map; @@ -33,37 +34,39 @@ public class RenameProcessor implements Processor { public static final String TYPE = "rename"; - private final Map fields; + private final String oldFieldName; + private final String newFieldName; - RenameProcessor(Map fields) { - this.fields = fields; + RenameProcessor(String oldFieldName, String newFieldName) { + this.oldFieldName = oldFieldName; + this.newFieldName = newFieldName; } - Map getFields() { - return fields; + String getOldFieldName() { + return oldFieldName; + } + + String getNewFieldName() { + return newFieldName; } @Override public void execute(IngestDocument document) { - for(Map.Entry entry : fields.entrySet()) { - String oldFieldName = entry.getKey(); - if (document.hasField(oldFieldName) == false) { - throw new IllegalArgumentException("field [" + oldFieldName + "] doesn't exist"); - } - String newFieldName = entry.getValue(); - if (document.hasField(newFieldName)) { - throw new IllegalArgumentException("field [" + newFieldName + "] already exists"); - } + if (document.hasField(oldFieldName) == false) { + throw new IllegalArgumentException("field [" + oldFieldName + "] doesn't exist"); + } + if (document.hasField(newFieldName)) { + throw new IllegalArgumentException("field [" + newFieldName + "] already exists"); + } - Object oldValue = document.getFieldValue(entry.getKey(), Object.class); - document.setFieldValue(newFieldName, oldValue); - try { - document.removeField(oldFieldName); - } catch (Exception e) { - //remove the new field if the removal of the old one failed - document.removeField(newFieldName); - throw e; - } + Object oldValue = document.getFieldValue(oldFieldName, Object.class); + document.setFieldValue(newFieldName, oldValue); + try { + document.removeField(oldFieldName); + } catch (Exception e) { + //remove the new field if the removal of the old one failed + document.removeField(newFieldName); + throw e; } } @@ -75,8 +78,9 @@ public class RenameProcessor implements Processor { public static class Factory implements Processor.Factory { @Override public RenameProcessor create(Map config) throws Exception { - Map fields = ConfigurationUtils.readMap(config, "fields"); - return new RenameProcessor(Collections.unmodifiableMap(fields)); + String field = ConfigurationUtils.readStringProperty(config, "field"); + String newField = ConfigurationUtils.readStringProperty(config, "to"); + return new RenameProcessor(field, newField); } } } diff --git a/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/set/SetProcessor.java b/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/set/SetProcessor.java index f46fe5052f5..f14be2a3217 100644 --- a/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/set/SetProcessor.java +++ b/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/set/SetProcessor.java @@ -23,6 +23,7 @@ import org.elasticsearch.ingest.IngestDocument; import org.elasticsearch.ingest.processor.ConfigurationUtils; import org.elasticsearch.ingest.processor.Processor; +import java.util.Arrays; import java.util.Collections; import java.util.Map; @@ -34,21 +35,25 @@ public class SetProcessor implements Processor { public static final String TYPE = "set"; - private final Map fields; + private final String field; + private final Object value; - SetProcessor(Map fields) { - this.fields = fields; + SetProcessor(String field, Object value) { + this.field = field; + this.value = value; } - Map getFields() { - return fields; + String getField() { + return field; + } + + Object getValue() { + return value; } @Override public void execute(IngestDocument document) { - for(Map.Entry entry : fields.entrySet()) { - document.setFieldValue(entry.getKey(), entry.getValue()); - } + document.setFieldValue(field, value); } @Override @@ -59,8 +64,9 @@ public class SetProcessor implements Processor { public static final class Factory implements Processor.Factory { @Override public SetProcessor create(Map config) throws Exception { - Map fields = ConfigurationUtils.readMap(config, "fields"); - return new SetProcessor(Collections.unmodifiableMap(fields)); + String field = ConfigurationUtils.readStringProperty(config, "field"); + Object value = ConfigurationUtils.readObject(config, "value"); + return new SetProcessor(field, value); } } } diff --git a/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/split/SplitProcessor.java b/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/split/SplitProcessor.java index 6d9dea24947..1895fc10d37 100644 --- a/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/split/SplitProcessor.java +++ b/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/split/SplitProcessor.java @@ -36,25 +36,29 @@ public class SplitProcessor implements Processor { public static final String TYPE = "split"; - private final Map fields; + private final String field; + private final String separator; - SplitProcessor(Map fields) { - this.fields = fields; + SplitProcessor(String field, String separator) { + this.field = field; + this.separator = separator; } - Map getFields() { - return fields; + String getField() { + return field; + } + + String getSeparator() { + return separator; } @Override public void execute(IngestDocument document) { - for(Map.Entry entry : fields.entrySet()) { - String oldVal = document.getFieldValue(entry.getKey(), String.class); - if (oldVal == null) { - throw new IllegalArgumentException("field [" + entry.getKey() + "] is null, cannot split."); - } - document.setFieldValue(entry.getKey(), Arrays.asList(oldVal.split(entry.getValue()))); + String oldVal = document.getFieldValue(field, String.class); + if (oldVal == null) { + throw new IllegalArgumentException("field [" + field + "] is null, cannot split."); } + document.setFieldValue(field, Arrays.asList(oldVal.split(separator))); } @Override @@ -65,8 +69,8 @@ public class SplitProcessor implements Processor { public static class Factory implements Processor.Factory { @Override public SplitProcessor create(Map config) throws Exception { - Map fields = ConfigurationUtils.readMap(config, "fields"); - return new SplitProcessor(Collections.unmodifiableMap(fields)); + String field = ConfigurationUtils.readStringProperty(config, "field"); + return new SplitProcessor(field, ConfigurationUtils.readStringProperty(config, "separator")); } } } diff --git a/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/trim/TrimProcessor.java b/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/trim/TrimProcessor.java index d3090a37d41..94b617ba41e 100644 --- a/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/trim/TrimProcessor.java +++ b/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/trim/TrimProcessor.java @@ -31,8 +31,8 @@ public class TrimProcessor extends AbstractStringProcessor { public static final String TYPE = "trim"; - TrimProcessor(Collection fields) { - super(fields); + TrimProcessor(String field) { + super(field); } @Override @@ -47,8 +47,8 @@ public class TrimProcessor extends AbstractStringProcessor { public static class Factory extends AbstractStringProcessor.Factory { @Override - protected TrimProcessor newProcessor(Collection fields) { - return new TrimProcessor(fields); + protected TrimProcessor newProcessor(String field) { + return new TrimProcessor(field); } } } diff --git a/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/uppercase/UppercaseProcessor.java b/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/uppercase/UppercaseProcessor.java index a4b281fe2e9..fe0d029cf3c 100644 --- a/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/uppercase/UppercaseProcessor.java +++ b/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/uppercase/UppercaseProcessor.java @@ -32,8 +32,8 @@ public class UppercaseProcessor extends AbstractStringProcessor { public static final String TYPE = "uppercase"; - UppercaseProcessor(Collection fields) { - super(fields); + UppercaseProcessor(String field) { + super(field); } @Override @@ -48,8 +48,8 @@ public class UppercaseProcessor extends AbstractStringProcessor { public static class Factory extends AbstractStringProcessor.Factory { @Override - protected UppercaseProcessor newProcessor(Collection fields) { - return new UppercaseProcessor(fields); + protected UppercaseProcessor newProcessor(String field) { + return new UppercaseProcessor(field); } } } diff --git a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/AbstractStringProcessorTestCase.java b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/AbstractStringProcessorTestCase.java index 3b80b5a38c6..6bb2f9dd0dc 100644 --- a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/AbstractStringProcessorTestCase.java +++ b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/AbstractStringProcessorTestCase.java @@ -33,7 +33,7 @@ import static org.hamcrest.Matchers.equalTo; public abstract class AbstractStringProcessorTestCase extends ESTestCase { - protected abstract AbstractStringProcessor newProcessor(Collection fields); + protected abstract AbstractStringProcessor newProcessor(String field); protected String modifyInput(String input) { return input; @@ -43,23 +43,16 @@ public abstract class AbstractStringProcessorTestCase extends ESTestCase { public void testProcessor() throws Exception { IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random()); - int numFields = randomIntBetween(1, 5); - Map expected = new HashMap<>(); - for (int i = 0; i < numFields; i++) { - String fieldValue = RandomDocumentPicks.randomString(random()); - String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, modifyInput(fieldValue)); - expected.put(fieldName, expectedResult(fieldValue)); - } - Processor processor = newProcessor(expected.keySet()); + String fieldValue = RandomDocumentPicks.randomString(random()); + String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, modifyInput(fieldValue)); + Processor processor = newProcessor(fieldName); processor.execute(ingestDocument); - for (Map.Entry entry : expected.entrySet()) { - assertThat(ingestDocument.getFieldValue(entry.getKey(), String.class), equalTo(entry.getValue())); - } + assertThat(ingestDocument.getFieldValue(fieldName, String.class), equalTo(expectedResult(fieldValue))); } public void testFieldNotFound() throws Exception { String fieldName = RandomDocumentPicks.randomFieldName(random()); - Processor processor = newProcessor(Collections.singletonList(fieldName)); + Processor processor = newProcessor(fieldName); IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>()); try { processor.execute(ingestDocument); @@ -70,7 +63,7 @@ public abstract class AbstractStringProcessorTestCase extends ESTestCase { } public void testNullValue() throws Exception { - Processor processor = newProcessor(Collections.singletonList("field")); + Processor processor = newProcessor("field"); IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap("field", null)); try { processor.execute(ingestDocument); @@ -82,7 +75,7 @@ public abstract class AbstractStringProcessorTestCase extends ESTestCase { public void testNonStringValue() throws Exception { String fieldName = RandomDocumentPicks.randomFieldName(random()); - Processor processor = newProcessor(Collections.singletonList(fieldName)); + Processor processor = newProcessor(fieldName); IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>()); ingestDocument.setFieldValue(fieldName, randomInt()); try { diff --git a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/convert/ConvertProcessorFactoryTests.java b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/convert/ConvertProcessorFactoryTests.java index 108d7104a0c..369e4d461de 100644 --- a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/convert/ConvertProcessorFactoryTests.java +++ b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/convert/ConvertProcessorFactoryTests.java @@ -34,30 +34,19 @@ public class ConvertProcessorFactoryTests extends ESTestCase { ConvertProcessor.Factory factory = new ConvertProcessor.Factory(); Map config = new HashMap<>(); ConvertProcessor.Type type = randomFrom(ConvertProcessor.Type.values()); - Map fields = Collections.singletonMap("field1", type.toString()); - config.put("fields", fields); + config.put("field", "field1"); + config.put("type", type.toString()); ConvertProcessor convertProcessor = factory.create(config); - assertThat(convertProcessor.getFields().size(), equalTo(1)); - assertThat(convertProcessor.getFields().get("field1"), equalTo(type)); - } - - public void testCreateMissingFields() throws Exception { - ConvertProcessor.Factory factory = new ConvertProcessor.Factory(); - Map config = new HashMap<>(); - try { - factory.create(config); - fail("factory create should have failed"); - } catch(IllegalArgumentException e) { - assertThat(e.getMessage(), equalTo("required property [fields] is missing")); - } + assertThat(convertProcessor.getField(), equalTo("field1")); + assertThat(convertProcessor.getConvertType(), equalTo(type)); } public void testCreateUnsupportedType() throws Exception { ConvertProcessor.Factory factory = new ConvertProcessor.Factory(); Map config = new HashMap<>(); String type = "type-" + randomAsciiOfLengthBetween(1, 10); - Map fields = Collections.singletonMap("field1", type); - config.put("fields", fields); + config.put("field", "field1"); + config.put("type", type); try { factory.create(config); fail("factory create should have failed"); @@ -65,4 +54,29 @@ public class ConvertProcessorFactoryTests extends ESTestCase { assertThat(e.getMessage(), Matchers.equalTo("type [" + type + "] not supported, cannot convert field.")); } } + + public void testCreateNoFieldPresent() throws Exception { + ConvertProcessor.Factory factory = new ConvertProcessor.Factory(); + Map config = new HashMap<>(); + String type = "type-" + randomAsciiOfLengthBetween(1, 10); + config.put("type", type); + try { + factory.create(config); + fail("factory create should have failed"); + } catch (IllegalArgumentException e) { + assertThat(e.getMessage(), Matchers.equalTo("required property [field] is missing")); + } + } + + public void testCreateNoTypePresent() throws Exception { + ConvertProcessor.Factory factory = new ConvertProcessor.Factory(); + Map config = new HashMap<>(); + config.put("field", "field1"); + try { + factory.create(config); + fail("factory create should have failed"); + } catch (IllegalArgumentException e) { + assertThat(e.getMessage(), Matchers.equalTo("required property [type] is missing")); + } + } } diff --git a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/convert/ConvertProcessorTests.java b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/convert/ConvertProcessorTests.java index 85dcf860e20..fe560656ce5 100644 --- a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/convert/ConvertProcessorTests.java +++ b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/convert/ConvertProcessorTests.java @@ -34,45 +34,27 @@ public class ConvertProcessorTests extends ESTestCase { public void testConvertInt() throws Exception { IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random()); - Map fields = new HashMap<>(); - Map expectedResult = new HashMap<>(); - int numFields = randomIntBetween(1, 5); - for (int i = 0; i < numFields; i++) { - int randomInt = randomInt(); - String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, randomInt); - fields.put(fieldName, Type.INTEGER); - expectedResult.put(fieldName, randomInt); - } - Processor processor = new ConvertProcessor(fields); + int randomInt = randomInt(); + String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, randomInt); + Processor processor = new ConvertProcessor(fieldName, Type.INTEGER); processor.execute(ingestDocument); - for (Map.Entry entry : expectedResult.entrySet()) { - assertThat(ingestDocument.getFieldValue(entry.getKey(), Integer.class), equalTo(entry.getValue())); - } + assertThat(ingestDocument.getFieldValue(fieldName, Integer.class), equalTo(randomInt)); } public void testConvertIntList() throws Exception { IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random()); - Map fields = new HashMap<>(); - Map> expectedResult = new HashMap<>(); - int numFields = randomIntBetween(1, 5); - for (int i = 0; i < numFields; i++) { - int numItems = randomIntBetween(1, 10); - List fieldValue = new ArrayList<>(); - List expectedList = new ArrayList<>(); - for (int j = 0; j < numItems; j++) { - int randomInt = randomInt(); - fieldValue.add(Integer.toString(randomInt)); - expectedList.add(randomInt); - } - String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue); - fields.put(fieldName, Type.INTEGER); - expectedResult.put(fieldName, expectedList); + int numItems = randomIntBetween(1, 10); + List fieldValue = new ArrayList<>(); + List expectedList = new ArrayList<>(); + for (int j = 0; j < numItems; j++) { + int randomInt = randomInt(); + fieldValue.add(Integer.toString(randomInt)); + expectedList.add(randomInt); } - Processor processor = new ConvertProcessor(fields); + String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue); + Processor processor = new ConvertProcessor(fieldName, Type.INTEGER); processor.execute(ingestDocument); - for (Map.Entry> entry : expectedResult.entrySet()) { - assertThat(ingestDocument.getFieldValue(entry.getKey(), List.class), equalTo(entry.getValue())); - } + assertThat(ingestDocument.getFieldValue(fieldName, List.class), equalTo(expectedList)); } public void testConvertIntError() throws Exception { @@ -81,8 +63,7 @@ public class ConvertProcessorTests extends ESTestCase { String value = "string-" + randomAsciiOfLengthBetween(1, 10); ingestDocument.setFieldValue(fieldName, value); - Map convert = Collections.singletonMap(fieldName, Type.INTEGER); - Processor processor = new ConvertProcessor(convert); + Processor processor = new ConvertProcessor(fieldName, Type.INTEGER); try { processor.execute(ingestDocument); fail("processor execute should have failed"); @@ -93,46 +74,30 @@ public class ConvertProcessorTests extends ESTestCase { public void testConvertFloat() throws Exception { IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random()); - Map fields = new HashMap<>(); Map expectedResult = new HashMap<>(); - int numFields = randomIntBetween(1, 5); - for (int i = 0; i < numFields; i++) { - float randomFloat = randomFloat(); - String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, randomFloat); - fields.put(fieldName, Type.FLOAT); - expectedResult.put(fieldName, randomFloat); - } + float randomFloat = randomFloat(); + String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, randomFloat); + expectedResult.put(fieldName, randomFloat); - Processor processor = new ConvertProcessor(fields); + Processor processor = new ConvertProcessor(fieldName, Type.FLOAT); processor.execute(ingestDocument); - for (Map.Entry entry : expectedResult.entrySet()) { - assertThat(ingestDocument.getFieldValue(entry.getKey(), Float.class), equalTo(entry.getValue())); - } + assertThat(ingestDocument.getFieldValue(fieldName, Float.class), equalTo(randomFloat)); } public void testConvertFloatList() throws Exception { IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random()); - Map fields = new HashMap<>(); - Map> expectedResult = new HashMap<>(); - int numFields = randomIntBetween(1, 5); - for (int i = 0; i < numFields; i++) { - int numItems = randomIntBetween(1, 10); - List fieldValue = new ArrayList<>(); - List expectedList = new ArrayList<>(); - for (int j = 0; j < numItems; j++) { - float randomFloat = randomFloat(); - fieldValue.add(Float.toString(randomFloat)); - expectedList.add(randomFloat); - } - String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue); - fields.put(fieldName, Type.FLOAT); - expectedResult.put(fieldName, expectedList); + int numItems = randomIntBetween(1, 10); + List fieldValue = new ArrayList<>(); + List expectedList = new ArrayList<>(); + for (int j = 0; j < numItems; j++) { + float randomFloat = randomFloat(); + fieldValue.add(Float.toString(randomFloat)); + expectedList.add(randomFloat); } - Processor processor = new ConvertProcessor(fields); + String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue); + Processor processor = new ConvertProcessor(fieldName, Type.FLOAT); processor.execute(ingestDocument); - for (Map.Entry> entry : expectedResult.entrySet()) { - assertThat(ingestDocument.getFieldValue(entry.getKey(), List.class), equalTo(entry.getValue())); - } + assertThat(ingestDocument.getFieldValue(fieldName, List.class), equalTo(expectedList)); } public void testConvertFloatError() throws Exception { @@ -141,8 +106,7 @@ public class ConvertProcessorTests extends ESTestCase { String value = "string-" + randomAsciiOfLengthBetween(1, 10); ingestDocument.setFieldValue(fieldName, value); - Map convert = Collections.singletonMap(fieldName, Type.FLOAT); - Processor processor = new ConvertProcessor(convert); + Processor processor = new ConvertProcessor(fieldName, Type.FLOAT); try { processor.execute(ingestDocument); fail("processor execute should have failed"); @@ -155,52 +119,36 @@ public class ConvertProcessorTests extends ESTestCase { IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random()); Map fields = new HashMap<>(); Map expectedResult = new HashMap<>(); - int numFields = randomIntBetween(1, 5); - for (int i = 0; i < numFields; i++) { + boolean randomBoolean = randomBoolean(); + String booleanString = Boolean.toString(randomBoolean); + if (randomBoolean) { + booleanString = booleanString.toUpperCase(Locale.ROOT); + } + String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, booleanString); + + Processor processor = new ConvertProcessor(fieldName, Type.BOOLEAN); + processor.execute(ingestDocument); + assertThat(ingestDocument.getFieldValue(fieldName, Boolean.class), equalTo(randomBoolean)); + } + + public void testConvertBooleanList() throws Exception { + IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random()); + int numItems = randomIntBetween(1, 10); + List fieldValue = new ArrayList<>(); + List expectedList = new ArrayList<>(); + for (int j = 0; j < numItems; j++) { boolean randomBoolean = randomBoolean(); String booleanString = Boolean.toString(randomBoolean); if (randomBoolean) { booleanString = booleanString.toUpperCase(Locale.ROOT); } - String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, booleanString); - fields.put(fieldName, Type.BOOLEAN); - expectedResult.put(fieldName, randomBoolean); + fieldValue.add(booleanString); + expectedList.add(randomBoolean); } - - Processor processor = new ConvertProcessor(fields); + String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue); + Processor processor = new ConvertProcessor(fieldName, Type.BOOLEAN); processor.execute(ingestDocument); - for (Map.Entry entry : expectedResult.entrySet()) { - assertThat(ingestDocument.getFieldValue(entry.getKey(), Boolean.class), equalTo(entry.getValue())); - } - } - - public void testConvertBooleanList() throws Exception { - IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random()); - Map fields = new HashMap<>(); - Map> expectedResult = new HashMap<>(); - int numFields = randomIntBetween(1, 5); - for (int i = 0; i < numFields; i++) { - int numItems = randomIntBetween(1, 10); - List fieldValue = new ArrayList<>(); - List expectedList = new ArrayList<>(); - for (int j = 0; j < numItems; j++) { - boolean randomBoolean = randomBoolean(); - String booleanString = Boolean.toString(randomBoolean); - if (randomBoolean) { - booleanString = booleanString.toUpperCase(Locale.ROOT); - } - fieldValue.add(booleanString); - expectedList.add(randomBoolean); - } - String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue); - fields.put(fieldName, Type.BOOLEAN); - expectedResult.put(fieldName, expectedList); - } - Processor processor = new ConvertProcessor(fields); - processor.execute(ingestDocument); - for (Map.Entry> entry : expectedResult.entrySet()) { - assertThat(ingestDocument.getFieldValue(entry.getKey(), List.class), equalTo(entry.getValue())); - } + assertThat(ingestDocument.getFieldValue(fieldName, List.class), equalTo(expectedList)); } public void testConvertBooleanError() throws Exception { @@ -215,8 +163,7 @@ public class ConvertProcessorTests extends ESTestCase { } ingestDocument.setFieldValue(fieldName, fieldValue); - Map convert = Collections.singletonMap(fieldName, Type.BOOLEAN); - Processor processor = new ConvertProcessor(convert); + Processor processor = new ConvertProcessor(fieldName, Type.BOOLEAN); try { processor.execute(ingestDocument); fail("processor execute should have failed"); @@ -227,94 +174,75 @@ public class ConvertProcessorTests extends ESTestCase { public void testConvertString() throws Exception { IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random()); - Map fields = new HashMap<>(); - Map expectedResult = new HashMap<>(); - int numFields = randomIntBetween(1, 5); - for (int i = 0; i < numFields; i++) { - Object fieldValue; - String expectedFieldValue; - switch(randomIntBetween(0, 2)) { - case 0: - float randomFloat = randomFloat(); - fieldValue = randomFloat; - expectedFieldValue = Float.toString(randomFloat); - break; - case 1: - int randomInt = randomInt(); - fieldValue = randomInt; - expectedFieldValue = Integer.toString(randomInt); - break; - case 2: - boolean randomBoolean = randomBoolean(); - fieldValue = randomBoolean; - expectedFieldValue = Boolean.toString(randomBoolean); - break; - default: - throw new UnsupportedOperationException(); - } - String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue); - fields.put(fieldName, Type.STRING); - expectedResult.put(fieldName, expectedFieldValue); + Object fieldValue; + String expectedFieldValue; + switch(randomIntBetween(0, 2)) { + case 0: + float randomFloat = randomFloat(); + fieldValue = randomFloat; + expectedFieldValue = Float.toString(randomFloat); + break; + case 1: + int randomInt = randomInt(); + fieldValue = randomInt; + expectedFieldValue = Integer.toString(randomInt); + break; + case 2: + boolean randomBoolean = randomBoolean(); + fieldValue = randomBoolean; + expectedFieldValue = Boolean.toString(randomBoolean); + break; + default: + throw new UnsupportedOperationException(); } + String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue); - Processor processor = new ConvertProcessor(fields); + Processor processor = new ConvertProcessor(fieldName, Type.STRING); processor.execute(ingestDocument); - for (Map.Entry entry : expectedResult.entrySet()) { - assertThat(ingestDocument.getFieldValue(entry.getKey(), String.class), equalTo(entry.getValue())); - } + assertThat(ingestDocument.getFieldValue(fieldName, String.class), equalTo(expectedFieldValue)); } public void testConvertStringList() throws Exception { IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random()); - Map fields = new HashMap<>(); - Map> expectedResult = new HashMap<>(); - int numFields = randomIntBetween(1, 5); - for (int i = 0; i < numFields; i++) { - int numItems = randomIntBetween(1, 10); - List fieldValue = new ArrayList<>(); - List expectedList = new ArrayList<>(); - for (int j = 0; j < numItems; j++) { - Object randomValue; - String randomValueString; - switch(randomIntBetween(0, 2)) { - case 0: - float randomFloat = randomFloat(); - randomValue = randomFloat; - randomValueString = Float.toString(randomFloat); - break; - case 1: - int randomInt = randomInt(); - randomValue = randomInt; - randomValueString = Integer.toString(randomInt); - break; - case 2: - boolean randomBoolean = randomBoolean(); - randomValue = randomBoolean; - randomValueString = Boolean.toString(randomBoolean); - break; - default: - throw new UnsupportedOperationException(); - } - fieldValue.add(randomValue); - expectedList.add(randomValueString); + int numItems = randomIntBetween(1, 10); + List fieldValue = new ArrayList<>(); + List expectedList = new ArrayList<>(); + for (int j = 0; j < numItems; j++) { + Object randomValue; + String randomValueString; + switch(randomIntBetween(0, 2)) { + case 0: + float randomFloat = randomFloat(); + randomValue = randomFloat; + randomValueString = Float.toString(randomFloat); + break; + case 1: + int randomInt = randomInt(); + randomValue = randomInt; + randomValueString = Integer.toString(randomInt); + break; + case 2: + boolean randomBoolean = randomBoolean(); + randomValue = randomBoolean; + randomValueString = Boolean.toString(randomBoolean); + break; + default: + throw new UnsupportedOperationException(); } - String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue); - fields.put(fieldName, Type.STRING); - expectedResult.put(fieldName, expectedList); + fieldValue.add(randomValue); + expectedList.add(randomValueString); } - Processor processor = new ConvertProcessor(fields); + String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue); + Processor processor = new ConvertProcessor(fieldName, Type.STRING); processor.execute(ingestDocument); - for (Map.Entry> entry : expectedResult.entrySet()) { - assertThat(ingestDocument.getFieldValue(entry.getKey(), List.class), equalTo(entry.getValue())); - } + assertThat(ingestDocument.getFieldValue(fieldName, List.class), equalTo(expectedList)); } public void testConvertNonExistingField() throws Exception { IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>()); String fieldName = RandomDocumentPicks.randomFieldName(random()); Type type = randomFrom(Type.values()); - Map convert = Collections.singletonMap(fieldName, type); - Processor processor = new ConvertProcessor(convert); + Processor processor = new ConvertProcessor(fieldName, type); try { processor.execute(ingestDocument); fail("processor execute should have failed"); @@ -326,8 +254,7 @@ public class ConvertProcessorTests extends ESTestCase { public void testConvertNullField() throws Exception { IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap("field", null)); Type type = randomFrom(Type.values()); - Map convert = Collections.singletonMap("field", type); - Processor processor = new ConvertProcessor(convert); + Processor processor = new ConvertProcessor("field", type); try { processor.execute(ingestDocument); fail("processor execute should have failed"); diff --git a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/gsub/GsubProcessorFactoryTests.java b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/gsub/GsubProcessorFactoryTests.java index c032a19347a..e1e085d135f 100644 --- a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/gsub/GsubProcessorFactoryTests.java +++ b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/gsub/GsubProcessorFactoryTests.java @@ -33,80 +33,51 @@ public class GsubProcessorFactoryTests extends ESTestCase { public void testCreate() throws Exception { GsubProcessor.Factory factory = new GsubProcessor.Factory(); Map config = new HashMap<>(); - List> expressions = new ArrayList<>(); - Map expression = new HashMap<>(); - expression.put("field", "field1"); - expression.put("pattern", "\\."); - expression.put("replacement", "-"); - expressions.add(expression); - config.put("expressions", expressions); + config.put("field", "field1"); + config.put("pattern", "\\."); + config.put("replacement", "-"); GsubProcessor gsubProcessor = factory.create(config); - assertThat(gsubProcessor.getGsubExpressions().size(), equalTo(1)); - GsubExpression gsubExpression = gsubProcessor.getGsubExpressions().get(0); - assertThat(gsubExpression.getFieldName(), equalTo("field1")); - assertThat(gsubExpression.getPattern().toString(), equalTo("\\.")); - assertThat(gsubExpression.getReplacement(), equalTo("-")); - } - - public void testCreateMissingExpressions() throws Exception { - GsubProcessor.Factory factory = new GsubProcessor.Factory(); - Map config = new HashMap<>(); - try { - factory.create(config); - fail("factory create should have failed"); - } catch(IllegalArgumentException e) { - assertThat(e.getMessage(), equalTo("required property [expressions] is missing")); - } + assertThat(gsubProcessor.getField(), equalTo("field1")); + assertThat(gsubProcessor.getPattern().toString(), equalTo("\\.")); + assertThat(gsubProcessor.getReplacement(), equalTo("-")); } public void testCreateNoFieldPresent() throws Exception { GsubProcessor.Factory factory = new GsubProcessor.Factory(); Map config = new HashMap<>(); - List> expressions = new ArrayList<>(); - Map expression = new HashMap<>(); - expression.put("pattern", "\\."); - expression.put("replacement", "-"); - expressions.add(expression); - config.put("expressions", expressions); + config.put("pattern", "\\."); + config.put("replacement", "-"); try { factory.create(config); fail("factory create should have failed"); } catch(IllegalArgumentException e) { - assertThat(e.getMessage(), equalTo("no [field] specified for gsub expression")); + assertThat(e.getMessage(), equalTo("required property [field] is missing")); } } public void testCreateNoPatternPresent() throws Exception { GsubProcessor.Factory factory = new GsubProcessor.Factory(); Map config = new HashMap<>(); - List> expressions = new ArrayList<>(); - Map expression = new HashMap<>(); - expression.put("field", "field1"); - expression.put("replacement", "-"); - expressions.add(expression); - config.put("expressions", expressions); + config.put("field", "field1"); + config.put("replacement", "-"); try { factory.create(config); fail("factory create should have failed"); } catch(IllegalArgumentException e) { - assertThat(e.getMessage(), equalTo("no [pattern] specified for gsub expression")); + assertThat(e.getMessage(), equalTo("required property [pattern] is missing")); } } public void testCreateNoReplacementPresent() throws Exception { GsubProcessor.Factory factory = new GsubProcessor.Factory(); Map config = new HashMap<>(); - List> expressions = new ArrayList<>(); - Map expression = new HashMap<>(); - expression.put("field", "field1"); - expression.put("pattern", "\\."); - expressions.add(expression); - config.put("expressions", expressions); + config.put("field", "field1"); + config.put("pattern", "\\."); try { factory.create(config); fail("factory create should have failed"); } catch(IllegalArgumentException e) { - assertThat(e.getMessage(), equalTo("no [replacement] specified for gsub expression")); + assertThat(e.getMessage(), equalTo("required property [replacement] is missing")); } } } diff --git a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/gsub/GsubProcessorTests.java b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/gsub/GsubProcessorTests.java index 89c77135687..8eb5be790ea 100644 --- a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/gsub/GsubProcessorTests.java +++ b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/gsub/GsubProcessorTests.java @@ -37,25 +37,17 @@ public class GsubProcessorTests extends ESTestCase { public void testGsub() throws Exception { IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random()); - int numFields = randomIntBetween(1, 5); - List expressions = new ArrayList<>(); - for (int i = 0; i < numFields; i++) { - String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, "127.0.0.1"); - expressions.add(new GsubExpression(fieldName, Pattern.compile("\\."), "-")); - } - Processor processor = new GsubProcessor(expressions); + String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, "127.0.0.1"); + Processor processor = new GsubProcessor(fieldName, Pattern.compile("\\."), "-"); processor.execute(ingestDocument); - for (GsubExpression expression : expressions) { - assertThat(ingestDocument.getFieldValue(expression.getFieldName(), String.class), equalTo("127-0-0-1")); - } + assertThat(ingestDocument.getFieldValue(fieldName, String.class), equalTo("127-0-0-1")); } public void testGsubNotAStringValue() throws Exception { IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>()); String fieldName = RandomDocumentPicks.randomFieldName(random()); ingestDocument.setFieldValue(fieldName, 123); - List gsubExpressions = Collections.singletonList(new GsubExpression(fieldName, Pattern.compile("\\."), "-")); - Processor processor = new GsubProcessor(gsubExpressions); + Processor processor = new GsubProcessor(fieldName, Pattern.compile("\\."), "-"); try { processor.execute(ingestDocument); fail("processor execution should have failed"); @@ -67,8 +59,7 @@ public class GsubProcessorTests extends ESTestCase { public void testGsubFieldNotFound() throws Exception { IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>()); String fieldName = RandomDocumentPicks.randomFieldName(random()); - List gsubExpressions = Collections.singletonList(new GsubExpression(fieldName, Pattern.compile("\\."), "-")); - Processor processor = new GsubProcessor(gsubExpressions); + Processor processor = new GsubProcessor(fieldName, Pattern.compile("\\."), "-"); try { processor.execute(ingestDocument); fail("processor execution should have failed"); @@ -79,8 +70,7 @@ public class GsubProcessorTests extends ESTestCase { public void testGsubNullValue() throws Exception { IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap("field", null)); - List gsubExpressions = Collections.singletonList(new GsubExpression("field", Pattern.compile("\\."), "-")); - Processor processor = new GsubProcessor(gsubExpressions); + Processor processor = new GsubProcessor("field", Pattern.compile("\\."), "-"); try { processor.execute(ingestDocument); fail("processor execution should have failed"); diff --git a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/join/JoinProcessorFactoryTests.java b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/join/JoinProcessorFactoryTests.java index 8ad05eec6f8..deebe50b9c5 100644 --- a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/join/JoinProcessorFactoryTests.java +++ b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/join/JoinProcessorFactoryTests.java @@ -21,7 +21,6 @@ package org.elasticsearch.ingest.processor.join; import org.elasticsearch.test.ESTestCase; -import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -32,20 +31,34 @@ public class JoinProcessorFactoryTests extends ESTestCase { public void testCreate() throws Exception { JoinProcessor.Factory factory = new JoinProcessor.Factory(); Map config = new HashMap<>(); - Map fields = Collections.singletonMap("field1", "-"); - config.put("fields", fields); + config.put("field", "field1"); + config.put("separator", "-"); JoinProcessor joinProcessor = factory.create(config); - assertThat(joinProcessor.getFields(), equalTo(fields)); + assertThat(joinProcessor.getField(), equalTo("field1")); + assertThat(joinProcessor.getSeparator(), equalTo("-")); } - public void testCreateMissingFields() throws Exception { + public void testCreateNoFieldPresent() throws Exception { JoinProcessor.Factory factory = new JoinProcessor.Factory(); Map config = new HashMap<>(); + config.put("separator", "-"); try { factory.create(config); fail("factory create should have failed"); - } catch(IllegalArgumentException e) { - assertThat(e.getMessage(), equalTo("required property [fields] is missing")); + } catch (IllegalArgumentException e) { + assertThat(e.getMessage(), equalTo("required property [field] is missing")); + } + } + + public void testCreateNoSeparatorPresent() throws Exception { + JoinProcessor.Factory factory = new JoinProcessor.Factory(); + Map config = new HashMap<>(); + config.put("field", "field1"); + try { + factory.create(config); + fail("factory create should have failed"); + } catch (IllegalArgumentException e) { + assertThat(e.getMessage(), equalTo("required property [separator] is missing")); } } } diff --git a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/join/JoinProcessorTests.java b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/join/JoinProcessorTests.java index 4df240ece45..df6c835b3c9 100644 --- a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/join/JoinProcessorTests.java +++ b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/join/JoinProcessorTests.java @@ -35,68 +35,49 @@ public class JoinProcessorTests extends ESTestCase { public void testJoinStrings() throws Exception { IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random()); - Map fields = new HashMap<>(); - Map expectedResultMap = new HashMap<>(); - int numFields = randomIntBetween(1, 5); - for (int i = 0; i < numFields; i++) { - int numItems = randomIntBetween(1, 10); - String separator = randomFrom(SEPARATORS); - List fieldValue = new ArrayList<>(numItems); - String expectedResult = ""; - for (int j = 0; j < numItems; j++) { - String value = randomAsciiOfLengthBetween(1, 10); - fieldValue.add(value); - expectedResult += value; - if (j < numItems - 1) { - expectedResult += separator; - } + int numItems = randomIntBetween(1, 10); + String separator = randomFrom(SEPARATORS); + List fieldValue = new ArrayList<>(numItems); + String expectedResult = ""; + for (int j = 0; j < numItems; j++) { + String value = randomAsciiOfLengthBetween(1, 10); + fieldValue.add(value); + expectedResult += value; + if (j < numItems - 1) { + expectedResult += separator; } - String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue); - expectedResultMap.put(fieldName, expectedResult); - fields.put(fieldName, separator); } - Processor processor = new JoinProcessor(fields); + String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue); + Processor processor = new JoinProcessor(fieldName, separator); processor.execute(ingestDocument); - for (Map.Entry entry : expectedResultMap.entrySet()) { - assertThat(ingestDocument.getFieldValue(entry.getKey(), String.class), equalTo(entry.getValue())); - } + assertThat(ingestDocument.getFieldValue(fieldName, String.class), equalTo(expectedResult)); } public void testJoinIntegers() throws Exception { IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random()); - Map fields = new HashMap<>(); - Map expectedResultMap = new HashMap<>(); - int numFields = randomIntBetween(1, 5); - for (int i = 0; i < numFields; i++) { - int numItems = randomIntBetween(1, 10); - String separator = randomFrom(SEPARATORS); - List fieldValue = new ArrayList<>(numItems); - String expectedResult = ""; - for (int j = 0; j < numItems; j++) { - int value = randomInt(); - fieldValue.add(value); - expectedResult += value; - if (j < numItems - 1) { - expectedResult += separator; - } + int numItems = randomIntBetween(1, 10); + String separator = randomFrom(SEPARATORS); + List fieldValue = new ArrayList<>(numItems); + String expectedResult = ""; + for (int j = 0; j < numItems; j++) { + int value = randomInt(); + fieldValue.add(value); + expectedResult += value; + if (j < numItems - 1) { + expectedResult += separator; } - String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue); - expectedResultMap.put(fieldName, expectedResult); - fields.put(fieldName, separator); } - Processor processor = new JoinProcessor(fields); + String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue); + Processor processor = new JoinProcessor(fieldName, separator); processor.execute(ingestDocument); - for (Map.Entry entry : expectedResultMap.entrySet()) { - assertThat(ingestDocument.getFieldValue(entry.getKey(), String.class), equalTo(entry.getValue())); - } + assertThat(ingestDocument.getFieldValue(fieldName, String.class), equalTo(expectedResult)); } public void testJoinNonListField() throws Exception { IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>()); String fieldName = RandomDocumentPicks.randomFieldName(random()); ingestDocument.setFieldValue(fieldName, randomAsciiOfLengthBetween(1, 10)); - Map join = Collections.singletonMap(fieldName, "-"); - Processor processor = new JoinProcessor(join); + Processor processor = new JoinProcessor(fieldName, "-"); try { processor.execute(ingestDocument); } catch(IllegalArgumentException e) { @@ -107,7 +88,7 @@ public class JoinProcessorTests extends ESTestCase { public void testJoinNonExistingField() throws Exception { IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>()); String fieldName = RandomDocumentPicks.randomFieldName(random()); - Processor processor = new JoinProcessor(Collections.singletonMap(fieldName, "-")); + Processor processor = new JoinProcessor(fieldName, "-"); try { processor.execute(ingestDocument); } catch(IllegalArgumentException e) { @@ -117,7 +98,7 @@ public class JoinProcessorTests extends ESTestCase { public void testJoinNullValue() throws Exception { IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap("field", null)); - Processor processor = new JoinProcessor(Collections.singletonMap("field", "-")); + Processor processor = new JoinProcessor("field", "-"); try { processor.execute(ingestDocument); } catch(IllegalArgumentException e) { diff --git a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/lowercase/LowercaseProcessorFactoryTests.java b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/lowercase/LowercaseProcessorFactoryTests.java index 2a18eddf64c..34864e38eea 100644 --- a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/lowercase/LowercaseProcessorFactoryTests.java +++ b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/lowercase/LowercaseProcessorFactoryTests.java @@ -33,20 +33,19 @@ public class LowercaseProcessorFactoryTests extends ESTestCase { public void testCreate() throws Exception { LowercaseProcessor.Factory factory = new LowercaseProcessor.Factory(); Map config = new HashMap<>(); - List fields = Collections.singletonList("field1"); - config.put("fields", fields); + config.put("field", "field1"); LowercaseProcessor uppercaseProcessor = factory.create(config); - assertThat(uppercaseProcessor.getFields(), equalTo(fields)); + assertThat(uppercaseProcessor.getField(), equalTo("field1")); } - public void testCreateMissingFields() throws Exception { + public void testCreateMissingField() throws Exception { LowercaseProcessor.Factory factory = new LowercaseProcessor.Factory(); Map config = new HashMap<>(); try { factory.create(config); fail("factory create should have failed"); } catch(IllegalArgumentException e) { - assertThat(e.getMessage(), equalTo("required property [fields] is missing")); + assertThat(e.getMessage(), equalTo("required property [field] is missing")); } } } diff --git a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/lowercase/LowercaseProcessorTests.java b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/lowercase/LowercaseProcessorTests.java index 07e14062764..6e85b338b1a 100644 --- a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/lowercase/LowercaseProcessorTests.java +++ b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/lowercase/LowercaseProcessorTests.java @@ -27,8 +27,8 @@ import java.util.Locale; public class LowercaseProcessorTests extends AbstractStringProcessorTestCase { @Override - protected AbstractStringProcessor newProcessor(Collection fields) { - return new LowercaseProcessor(fields); + protected AbstractStringProcessor newProcessor(String field) { + return new LowercaseProcessor(field); } @Override diff --git a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/remove/RemoveProcessorFactoryTests.java b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/remove/RemoveProcessorFactoryTests.java index 27933ea66e3..f45f3bc59d0 100644 --- a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/remove/RemoveProcessorFactoryTests.java +++ b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/remove/RemoveProcessorFactoryTests.java @@ -33,20 +33,19 @@ public class RemoveProcessorFactoryTests extends ESTestCase { public void testCreate() throws Exception { RemoveProcessor.Factory factory = new RemoveProcessor.Factory(); Map config = new HashMap<>(); - List fields = Collections.singletonList("field1"); - config.put("fields", fields); + config.put("field", "field1"); RemoveProcessor removeProcessor = factory.create(config); - assertThat(removeProcessor.getFields(), equalTo(fields)); + assertThat(removeProcessor.getField(), equalTo("field1")); } - public void testCreateMissingFields() throws Exception { + public void testCreateMissingField() throws Exception { RemoveProcessor.Factory factory = new RemoveProcessor.Factory(); Map config = new HashMap<>(); try { factory.create(config); fail("factory create should have failed"); } catch(IllegalArgumentException e) { - assertThat(e.getMessage(), equalTo("required property [fields] is missing")); + assertThat(e.getMessage(), equalTo("required property [field] is missing")); } } } diff --git a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/remove/RemoveProcessorTests.java b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/remove/RemoveProcessorTests.java index 50b1ee198f9..2ccfd5add93 100644 --- a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/remove/RemoveProcessorTests.java +++ b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/remove/RemoveProcessorTests.java @@ -36,22 +36,16 @@ public class RemoveProcessorTests extends ESTestCase { public void testRemoveFields() throws Exception { IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random()); - int numFields = randomIntBetween(1, 5); - Set fields = new HashSet<>(); - for (int i = 0; i < numFields; i++) { - fields.add(RandomDocumentPicks.randomExistingFieldName(random(), ingestDocument)); - } - Processor processor = new RemoveProcessor(fields); + String field = RandomDocumentPicks.randomExistingFieldName(random(), ingestDocument); + Processor processor = new RemoveProcessor(field); processor.execute(ingestDocument); - for (String field : fields) { - assertThat(ingestDocument.hasField(field), equalTo(false)); - } + assertThat(ingestDocument.hasField(field), equalTo(false)); } public void testRemoveNonExistingField() throws Exception { IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>()); String fieldName = RandomDocumentPicks.randomFieldName(random()); - Processor processor = new RemoveProcessor(Collections.singletonList(fieldName)); + Processor processor = new RemoveProcessor(fieldName); try { processor.execute(ingestDocument); fail("remove field should have failed"); diff --git a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/rename/RenameProcessorFactoryTests.java b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/rename/RenameProcessorFactoryTests.java index d858b4aea07..eba08ad6c46 100644 --- a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/rename/RenameProcessorFactoryTests.java +++ b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/rename/RenameProcessorFactoryTests.java @@ -32,20 +32,34 @@ public class RenameProcessorFactoryTests extends ESTestCase { public void testCreate() throws Exception { RenameProcessor.Factory factory = new RenameProcessor.Factory(); Map config = new HashMap<>(); - Map fields = Collections.singletonMap("field1", "value1"); - config.put("fields", fields); + config.put("field", "old_field"); + config.put("to", "new_field"); RenameProcessor renameProcessor = factory.create(config); - assertThat(renameProcessor.getFields(), equalTo(fields)); + assertThat(renameProcessor.getOldFieldName(), equalTo("old_field")); + assertThat(renameProcessor.getNewFieldName(), equalTo("new_field")); } - public void testCreateMissingFields() throws Exception { + public void testCreateNoFieldPresent() throws Exception { RenameProcessor.Factory factory = new RenameProcessor.Factory(); Map config = new HashMap<>(); + config.put("to", "new_field"); try { factory.create(config); fail("factory create should have failed"); } catch(IllegalArgumentException e) { - assertThat(e.getMessage(), equalTo("required property [fields] is missing")); + assertThat(e.getMessage(), equalTo("required property [field] is missing")); + } + } + + public void testCreateNoToPresent() throws Exception { + RenameProcessor.Factory factory = new RenameProcessor.Factory(); + Map config = new HashMap<>(); + config.put("field", "old_field"); + try { + factory.create(config); + fail("factory create should have failed"); + } catch(IllegalArgumentException e) { + assertThat(e.getMessage(), equalTo("required property [to] is missing")); } } } diff --git a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/rename/RenameProcessorTests.java b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/rename/RenameProcessorTests.java index 338a5ff8f60..2feacc88190 100644 --- a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/rename/RenameProcessorTests.java +++ b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/rename/RenameProcessorTests.java @@ -34,26 +34,15 @@ public class RenameProcessorTests extends ESTestCase { public void testRename() throws Exception { IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random()); - int numFields = randomIntBetween(1, 5); - Map fields = new HashMap<>(); - Map newFields = new HashMap<>(); - for (int i = 0; i < numFields; i++) { - String fieldName = RandomDocumentPicks.randomExistingFieldName(random(), ingestDocument); - if (fields.containsKey(fieldName)) { - continue; - } - String newFieldName; - do { - newFieldName = RandomDocumentPicks.randomFieldName(random()); - } while (RandomDocumentPicks.canAddField(newFieldName, ingestDocument) == false || newFields.containsKey(newFieldName)); - newFields.put(newFieldName, ingestDocument.getFieldValue(fieldName, Object.class)); - fields.put(fieldName, newFieldName); - } - Processor processor = new RenameProcessor(fields); + String fieldName = RandomDocumentPicks.randomExistingFieldName(random(), ingestDocument); + Object fieldValue = ingestDocument.getFieldValue(fieldName, Object.class); + String newFieldName; + do { + newFieldName = RandomDocumentPicks.randomFieldName(random()); + } while (RandomDocumentPicks.canAddField(newFieldName, ingestDocument) == false || newFieldName.equals(fieldName)); + Processor processor = new RenameProcessor(fieldName, newFieldName); processor.execute(ingestDocument); - for (Map.Entry entry : newFields.entrySet()) { - assertThat(ingestDocument.getFieldValue(entry.getKey(), Object.class), equalTo(entry.getValue())); - } + assertThat(ingestDocument.getFieldValue(newFieldName, Object.class), equalTo(fieldValue)); } public void testRenameArrayElement() throws Exception { @@ -69,7 +58,7 @@ public class RenameProcessorTests extends ESTestCase { document.put("one", one); IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document); - Processor processor = new RenameProcessor(Collections.singletonMap("list.0", "item")); + Processor processor = new RenameProcessor("list.0", "item"); processor.execute(ingestDocument); Object actualObject = ingestDocument.getSource().get("list"); assertThat(actualObject, instanceOf(List.class)); @@ -82,7 +71,7 @@ public class RenameProcessorTests extends ESTestCase { assertThat(actualObject, instanceOf(String.class)); assertThat(actualObject, equalTo("item1")); - processor = new RenameProcessor(Collections.singletonMap("list.0", "list.3")); + processor = new RenameProcessor("list.0", "list.3"); try { processor.execute(ingestDocument); fail("processor execute should have failed"); @@ -97,7 +86,7 @@ public class RenameProcessorTests extends ESTestCase { public void testRenameNonExistingField() throws Exception { IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>()); String fieldName = RandomDocumentPicks.randomFieldName(random()); - Processor processor = new RenameProcessor(Collections.singletonMap(fieldName, RandomDocumentPicks.randomFieldName(random()))); + Processor processor = new RenameProcessor(fieldName, RandomDocumentPicks.randomFieldName(random())); try { processor.execute(ingestDocument); fail("processor execute should have failed"); @@ -109,7 +98,7 @@ public class RenameProcessorTests extends ESTestCase { public void testRenameNewFieldAlreadyExists() throws Exception { IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random()); String fieldName = RandomDocumentPicks.randomExistingFieldName(random(), ingestDocument); - Processor processor = new RenameProcessor(Collections.singletonMap(RandomDocumentPicks.randomExistingFieldName(random(), ingestDocument), fieldName)); + Processor processor = new RenameProcessor(RandomDocumentPicks.randomExistingFieldName(random(), ingestDocument), fieldName); try { processor.execute(ingestDocument); fail("processor execute should have failed"); @@ -123,7 +112,7 @@ public class RenameProcessorTests extends ESTestCase { String fieldName = RandomDocumentPicks.randomFieldName(random()); ingestDocument.setFieldValue(fieldName, null); String newFieldName = RandomDocumentPicks.randomFieldName(random()); - Processor processor = new RenameProcessor(Collections.singletonMap(fieldName, newFieldName)); + Processor processor = new RenameProcessor(fieldName, newFieldName); processor.execute(ingestDocument); assertThat(ingestDocument.hasField(fieldName), equalTo(false)); assertThat(ingestDocument.hasField(newFieldName), equalTo(true)); @@ -144,7 +133,7 @@ public class RenameProcessorTests extends ESTestCase { document.put("list", Collections.singletonList("item")); IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document); - Processor processor = new RenameProcessor(Collections.singletonMap("list", "new_field")); + Processor processor = new RenameProcessor("list", "new_field"); try { processor.execute(ingestDocument); fail("processor execute should have failed"); @@ -169,7 +158,7 @@ public class RenameProcessorTests extends ESTestCase { document.put("list", Collections.singletonList("item")); IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document); - Processor processor = new RenameProcessor(Collections.singletonMap("list", "new_field")); + Processor processor = new RenameProcessor("list", "new_field"); try { processor.execute(ingestDocument); fail("processor execute should have failed"); diff --git a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/set/SetProcessorFactoryTests.java b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/set/SetProcessorFactoryTests.java index 1f3c345b1db..9eb6b2a4907 100644 --- a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/set/SetProcessorFactoryTests.java +++ b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/set/SetProcessorFactoryTests.java @@ -32,20 +32,47 @@ public class SetProcessorFactoryTests extends ESTestCase { public void testCreate() throws Exception { SetProcessor.Factory factory = new SetProcessor.Factory(); Map config = new HashMap<>(); - Map fields = Collections.singletonMap("field1", "value1"); - config.put("fields", fields); + config.put("field", "field1"); + config.put("value", "value1"); SetProcessor setProcessor = factory.create(config); - assertThat(setProcessor.getFields(), equalTo(fields)); + assertThat(setProcessor.getField(), equalTo("field1")); + assertThat(setProcessor.getValue(), equalTo("value1")); } - public void testCreateMissingFields() throws Exception { + public void testCreateNoFieldPresent() throws Exception { SetProcessor.Factory factory = new SetProcessor.Factory(); Map config = new HashMap<>(); + config.put("value", "value1"); try { factory.create(config); fail("factory create should have failed"); } catch(IllegalArgumentException e) { - assertThat(e.getMessage(), equalTo("required property [fields] is missing")); + assertThat(e.getMessage(), equalTo("required property [field] is missing")); + } + } + + public void testCreateNoValuePresent() throws Exception { + SetProcessor.Factory factory = new SetProcessor.Factory(); + Map config = new HashMap<>(); + config.put("field", "field1"); + try { + factory.create(config); + fail("factory create should have failed"); + } catch(IllegalArgumentException e) { + assertThat(e.getMessage(), equalTo("required property [value] is missing")); + } + } + + public void testCreateNullValue() throws Exception { + SetProcessor.Factory factory = new SetProcessor.Factory(); + Map config = new HashMap<>(); + config.put("field", "field1"); + config.put("value", null); + try { + factory.create(config); + fail("factory create should have failed"); + } catch(IllegalArgumentException e) { + assertThat(e.getMessage(), equalTo("required property [value] is missing")); } } } diff --git a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/set/SetProcessorTests.java b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/set/SetProcessorTests.java index c675c9c51eb..7d693066595 100644 --- a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/set/SetProcessorTests.java +++ b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/set/SetProcessorTests.java @@ -32,45 +32,30 @@ public class SetProcessorTests extends ESTestCase { public void testSetExistingFields() throws Exception { IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random()); - int numFields = randomIntBetween(1, 5); - Map fields = new HashMap<>(); - for (int i = 0; i < numFields; i++) { - String fieldName = RandomDocumentPicks.randomExistingFieldName(random(), ingestDocument); - Object fieldValue = RandomDocumentPicks.randomFieldValue(random()); - fields.put(fieldName, fieldValue); - } - Processor processor = new SetProcessor(fields); + String fieldName = RandomDocumentPicks.randomExistingFieldName(random(), ingestDocument); + Object fieldValue = RandomDocumentPicks.randomFieldValue(random()); + Processor processor = new SetProcessor(fieldName, fieldValue); processor.execute(ingestDocument); - - for (Map.Entry field : fields.entrySet()) { - assertThat(ingestDocument.hasField(field.getKey()), equalTo(true)); - assertThat(ingestDocument.getFieldValue(field.getKey(), Object.class), equalTo(field.getValue())); - } + assertThat(ingestDocument.hasField(fieldName), equalTo(true)); + assertThat(ingestDocument.getFieldValue(fieldName, Object.class), equalTo(fieldValue)); } public void testSetNewFields() throws Exception { IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>()); //used to verify that there are no conflicts between subsequent fields going to be added IngestDocument testIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>()); - int numFields = randomIntBetween(1, 5); - Map fields = new HashMap<>(); - for (int i = 0; i < numFields; i++) { - Object fieldValue = RandomDocumentPicks.randomFieldValue(random()); - String fieldName = RandomDocumentPicks.addRandomField(random(), testIngestDocument, fieldValue); - fields.put(fieldName, fieldValue); - } - Processor processor = new SetProcessor(fields); + Object fieldValue = RandomDocumentPicks.randomFieldValue(random()); + String fieldName = RandomDocumentPicks.addRandomField(random(), testIngestDocument, fieldValue); + Processor processor = new SetProcessor(fieldName, fieldValue); processor.execute(ingestDocument); - for (Map.Entry field : fields.entrySet()) { - assertThat(ingestDocument.hasField(field.getKey()), equalTo(true)); - assertThat(ingestDocument.getFieldValue(field.getKey(), Object.class), equalTo(field.getValue())); - } + assertThat(ingestDocument.hasField(fieldName), equalTo(true)); + assertThat(ingestDocument.getFieldValue(fieldName, Object.class), equalTo(fieldValue)); } public void testSetFieldsTypeMismatch() throws Exception { IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>()); ingestDocument.setFieldValue("field", "value"); - Processor processor = new SetProcessor(Collections.singletonMap("field.inner", "value")); + Processor processor = new SetProcessor("field.inner", "value"); try { processor.execute(ingestDocument); fail("processor execute should have failed"); diff --git a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/split/SplitProcessorFactoryTests.java b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/split/SplitProcessorFactoryTests.java index e1c80859ac0..4d6634b8568 100644 --- a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/split/SplitProcessorFactoryTests.java +++ b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/split/SplitProcessorFactoryTests.java @@ -32,20 +32,34 @@ public class SplitProcessorFactoryTests extends ESTestCase { public void testCreate() throws Exception { SplitProcessor.Factory factory = new SplitProcessor.Factory(); Map config = new HashMap<>(); - Map fields = Collections.singletonMap("field1", "\\."); - config.put("fields", fields); + config.put("field", "field1"); + config.put("separator", "\\."); SplitProcessor splitProcessor = factory.create(config); - assertThat(splitProcessor.getFields(), equalTo(fields)); + assertThat(splitProcessor.getField(), equalTo("field1")); + assertThat(splitProcessor.getSeparator(), equalTo("\\.")); } - public void testCreateMissingFields() throws Exception { + public void testCreateNoFieldPresent() throws Exception { SplitProcessor.Factory factory = new SplitProcessor.Factory(); Map config = new HashMap<>(); + config.put("separator", "\\."); try { factory.create(config); fail("factory create should have failed"); } catch(IllegalArgumentException e) { - assertThat(e.getMessage(), equalTo("required property [fields] is missing")); + assertThat(e.getMessage(), equalTo("required property [field] is missing")); + } + } + + public void testCreateNoSeparatorPresent() throws Exception { + SplitProcessor.Factory factory = new SplitProcessor.Factory(); + Map config = new HashMap<>(); + config.put("field", "field1"); + try { + factory.create(config); + fail("factory create should have failed"); + } catch(IllegalArgumentException e) { + assertThat(e.getMessage(), equalTo("required property [separator] is missing")); } } } diff --git a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/split/SplitProcessorTests.java b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/split/SplitProcessorTests.java index a190dddc791..594ba3b4590 100644 --- a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/split/SplitProcessorTests.java +++ b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/split/SplitProcessorTests.java @@ -33,24 +33,16 @@ public class SplitProcessorTests extends ESTestCase { public void testSplit() throws Exception { IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random()); - Map fields = new HashMap<>(); - int numFields = randomIntBetween(1, 5); - for (int i = 0; i < numFields; i++) { - String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, "127.0.0.1"); - fields.put(fieldName, "\\."); - } - Processor processor = new SplitProcessor(fields); + String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, "127.0.0.1"); + Processor processor = new SplitProcessor(fieldName, "\\."); processor.execute(ingestDocument); - for (String field : fields.keySet()) { - assertThat(ingestDocument.getFieldValue(field, List.class), equalTo(Arrays.asList("127", "0", "0", "1"))); - } + assertThat(ingestDocument.getFieldValue(fieldName, List.class), equalTo(Arrays.asList("127", "0", "0", "1"))); } public void testSplitFieldNotFound() throws Exception { IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>()); String fieldName = RandomDocumentPicks.randomFieldName(random()); - Map split = Collections.singletonMap(fieldName, "\\."); - Processor processor = new SplitProcessor(split); + Processor processor = new SplitProcessor(fieldName, "\\."); try { processor.execute(ingestDocument); fail("split processor should have failed"); @@ -61,8 +53,7 @@ public class SplitProcessorTests extends ESTestCase { public void testSplitNullValue() throws Exception { IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap("field", null)); - Map split = Collections.singletonMap("field", "\\."); - Processor processor = new SplitProcessor(split); + Processor processor = new SplitProcessor("field", "\\."); try { processor.execute(ingestDocument); fail("split processor should have failed"); @@ -75,7 +66,7 @@ public class SplitProcessorTests extends ESTestCase { IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>()); String fieldName = RandomDocumentPicks.randomFieldName(random()); ingestDocument.setFieldValue(fieldName, randomInt()); - Processor processor = new SplitProcessor(Collections.singletonMap(fieldName, "\\.")); + Processor processor = new SplitProcessor(fieldName, "\\."); try { processor.execute(ingestDocument); fail("split processor should have failed"); diff --git a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/trim/TrimProcessorFactoryTests.java b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/trim/TrimProcessorFactoryTests.java index 2475b04db77..169ebda0064 100644 --- a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/trim/TrimProcessorFactoryTests.java +++ b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/trim/TrimProcessorFactoryTests.java @@ -33,20 +33,19 @@ public class TrimProcessorFactoryTests extends ESTestCase { public void testCreate() throws Exception { TrimProcessor.Factory factory = new TrimProcessor.Factory(); Map config = new HashMap<>(); - List fields = Collections.singletonList("field1"); - config.put("fields", fields); + config.put("field", "field1"); TrimProcessor uppercaseProcessor = factory.create(config); - assertThat(uppercaseProcessor.getFields(), equalTo(fields)); + assertThat(uppercaseProcessor.getField(), equalTo("field1")); } - public void testCreateMissingFields() throws Exception { + public void testCreateMissingField() throws Exception { TrimProcessor.Factory factory = new TrimProcessor.Factory(); Map config = new HashMap<>(); try { factory.create(config); fail("factory create should have failed"); } catch(IllegalArgumentException e) { - assertThat(e.getMessage(), equalTo("required property [fields] is missing")); + assertThat(e.getMessage(), equalTo("required property [field] is missing")); } } } diff --git a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/trim/TrimProcessorTests.java b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/trim/TrimProcessorTests.java index 586b9e5b4e3..eea867e57bd 100644 --- a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/trim/TrimProcessorTests.java +++ b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/trim/TrimProcessorTests.java @@ -22,13 +22,11 @@ package org.elasticsearch.ingest.processor.trim; import org.elasticsearch.ingest.processor.AbstractStringProcessor; import org.elasticsearch.ingest.processor.AbstractStringProcessorTestCase; -import java.util.Collection; - public class TrimProcessorTests extends AbstractStringProcessorTestCase { @Override - protected AbstractStringProcessor newProcessor(Collection fields) { - return new TrimProcessor(fields); + protected AbstractStringProcessor newProcessor(String field) { + return new TrimProcessor(field); } @Override diff --git a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/uppercase/UppercaseProcessorFactoryTests.java b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/uppercase/UppercaseProcessorFactoryTests.java index ec38b65d86a..a8e048bdcf2 100644 --- a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/uppercase/UppercaseProcessorFactoryTests.java +++ b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/uppercase/UppercaseProcessorFactoryTests.java @@ -33,20 +33,19 @@ public class UppercaseProcessorFactoryTests extends ESTestCase { public void testCreate() throws Exception { UppercaseProcessor.Factory factory = new UppercaseProcessor.Factory(); Map config = new HashMap<>(); - List fields = Collections.singletonList("field1"); - config.put("fields", fields); + config.put("field", "field1"); UppercaseProcessor uppercaseProcessor = factory.create(config); - assertThat(uppercaseProcessor.getFields(), equalTo(fields)); + assertThat(uppercaseProcessor.getField(), equalTo("field1")); } - public void testCreateMissingFields() throws Exception { + public void testCreateMissingField() throws Exception { UppercaseProcessor.Factory factory = new UppercaseProcessor.Factory(); Map config = new HashMap<>(); try { factory.create(config); fail("factory create should have failed"); } catch(IllegalArgumentException e) { - assertThat(e.getMessage(), equalTo("required property [fields] is missing")); + assertThat(e.getMessage(), equalTo("required property [field] is missing")); } } } diff --git a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/uppercase/UppercaseProcessorTests.java b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/uppercase/UppercaseProcessorTests.java index f23f21ece74..00e4d1826ca 100644 --- a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/uppercase/UppercaseProcessorTests.java +++ b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/uppercase/UppercaseProcessorTests.java @@ -28,8 +28,8 @@ import java.util.Locale; public class UppercaseProcessorTests extends AbstractStringProcessorTestCase { @Override - protected AbstractStringProcessor newProcessor(Collection fields) { - return new UppercaseProcessor(fields); + protected AbstractStringProcessor newProcessor(String field) { + return new UppercaseProcessor(field); } @Override diff --git a/plugins/ingest/src/test/resources/rest-api-spec/test/ingest/20_crud.yaml b/plugins/ingest/src/test/resources/rest-api-spec/test/ingest/20_crud.yaml index cc2cee0c742..607bed4d35f 100644 --- a/plugins/ingest/src/test/resources/rest-api-spec/test/ingest/20_crud.yaml +++ b/plugins/ingest/src/test/resources/rest-api-spec/test/ingest/20_crud.yaml @@ -13,9 +13,8 @@ "processors": [ { "set" : { - "fields" : { - "field2": "_value" - } + "field" : "field2", + "value": "_value" } } ] diff --git a/plugins/ingest/src/test/resources/rest-api-spec/test/ingest/60_mutate.yaml b/plugins/ingest/src/test/resources/rest-api-spec/test/ingest/60_mutate.yaml index a6126ddca45..eb59cada2d0 100644 --- a/plugins/ingest/src/test/resources/rest-api-spec/test/ingest/60_mutate.yaml +++ b/plugins/ingest/src/test/resources/rest-api-spec/test/ingest/60_mutate.yaml @@ -13,76 +13,59 @@ "processors": [ { "set" : { - "fields" : { - "new_field": "new_value" - } + "field" : "new_field", + "value": "new_value" } }, { "rename" : { - "fields" : { - "field_to_rename": "renamed_field" - } + "field" : "field_to_rename", + "to": "renamed_field" } }, { "remove" : { - "fields" : [ - "field_to_remove" - ] + "field" : "field_to_remove" } }, { "lowercase" : { - "fields" : [ - "field_to_lowercase" - ] + "field" : "field_to_lowercase" } }, { "uppercase" : { - "fields" : [ - "field_to_uppercase" - ] + "field" : "field_to_uppercase" } }, { "trim" : { - "fields" : [ - "field_to_trim" - ] + "field" : "field_to_trim" } }, { "split" : { - "fields" : { - "field_to_split": "-" - } + "field" : "field_to_split", + "separator": "-" } }, { "join" : { - "fields" : { - "field_to_join": "-" - } + "field" : "field_to_join", + "separator": "-" } }, { "convert" : { - "fields" : { - "field_to_convert": "integer" - } + "field" : "field_to_convert", + "type": "integer" } }, { "gsub" : { - "expressions" : [ - { - "field": "field_to_gsub", - "pattern" : "-", - "replacement" : "." - } - ] + "field": "field_to_gsub", + "pattern" : "-", + "replacement" : "." } } ] diff --git a/plugins/ingest/src/test/resources/rest-api-spec/test/ingest/80_simulate.yaml b/plugins/ingest/src/test/resources/rest-api-spec/test/ingest/80_simulate.yaml index c84f525af28..06873116db2 100644 --- a/plugins/ingest/src/test/resources/rest-api-spec/test/ingest/80_simulate.yaml +++ b/plugins/ingest/src/test/resources/rest-api-spec/test/ingest/80_simulate.yaml @@ -13,9 +13,8 @@ "processors": [ { "set" : { - "fields" : { - "field2" : "_value" - } + "field" : "field2", + "value" : "_value" } } ] @@ -67,9 +66,8 @@ "processors": [ { "set" : { - "fields" : { - "field2" : "_value" - } + "field" : "field2", + "value" : "_value" } } ] @@ -130,16 +128,14 @@ "processors": [ { "set" : { - "fields" : { - "field2" : "_value" - } + "field" : "field2", + "value" : "_value" } }, { "set" : { - "fields" : { - "field3" : "third_val" - } + "field" : "field3", + "value" : "third_val" } } ] @@ -182,7 +178,7 @@ "processors": [ { "uppercase" : { - "fields" : ["foo"] + "field" : "foo" } } ] @@ -227,14 +223,13 @@ "processors": [ { "convert" : { - "fields" : { - "foo": "integer" - } + "field" : "foo", + "type" : "integer" } }, { "uppercase" : { - "fields" : ["bar"] + "field" : "bar" } } ]