From e5074e2b1b8891eed9672645a85ff6ca706cb58c Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Thu, 24 Mar 2016 08:48:46 +0100 Subject: [PATCH] Make `parseMultiField` part of `parseField`. #17313 All our fields are supposed to support multi fields, so we could put the logic in `TypeParsers.parseField` instead of duplicating the logic in every type parser. --- .../index/mapper/core/BooleanFieldMapper.java | 2 -- .../index/mapper/core/KeywordFieldMapper.java | 2 -- .../index/mapper/core/StringFieldMapper.java | 2 -- .../index/mapper/core/TextFieldMapper.java | 2 -- .../elasticsearch/index/mapper/core/TypeParsers.java | 2 ++ .../index/mapper/geo/BaseGeoPointFieldMapper.java | 2 -- .../index/mapper/externalvalues/ExternalMapper.java | 10 ---------- 7 files changed, 2 insertions(+), 20 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/index/mapper/core/BooleanFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/core/BooleanFieldMapper.java index 29c37eee271..02d6a536812 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/core/BooleanFieldMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/core/BooleanFieldMapper.java @@ -110,8 +110,6 @@ public class BooleanFieldMapper extends FieldMapper { } builder.nullValue(lenientNodeBooleanValue(propNode)); iterator.remove(); - } else if (parseMultiField(builder, name, parserContext, propName, propNode)) { - iterator.remove(); } } return builder; diff --git a/core/src/main/java/org/elasticsearch/index/mapper/core/KeywordFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/core/KeywordFieldMapper.java index a3da79341a0..ab36b738c83 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/core/KeywordFieldMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/core/KeywordFieldMapper.java @@ -134,8 +134,6 @@ public final class KeywordFieldMapper extends FieldMapper implements AllFieldMap } else if (propName.equals("eager_global_ordinals")) { builder.eagerGlobalOrdinals(XContentMapValues.nodeBooleanValue(propNode)); iterator.remove(); - } else if (parseMultiField(builder, name, parserContext, propName, propNode)) { - iterator.remove(); } } return builder; diff --git a/core/src/main/java/org/elasticsearch/index/mapper/core/StringFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/core/StringFieldMapper.java index d19c6e31b0a..c87efcd9218 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/core/StringFieldMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/core/StringFieldMapper.java @@ -334,8 +334,6 @@ public class StringFieldMapper extends FieldMapper implements AllFieldMapper.Inc builder.fielddataFrequencyFilter(minFrequency, maxFrequency, minSegmentSize); DocumentMapperParser.checkNoRemainingFields(propName, frequencyFilter, parserContext.indexVersionCreated()); iterator.remove(); - } else if (parseMultiField(builder, fieldName, parserContext, propName, propNode)) { - iterator.remove(); } } return builder; diff --git a/core/src/main/java/org/elasticsearch/index/mapper/core/TextFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/core/TextFieldMapper.java index 582ae6aff38..0baa4564b69 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/core/TextFieldMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/core/TextFieldMapper.java @@ -163,8 +163,6 @@ public class TextFieldMapper extends FieldMapper implements AllFieldMapper.Inclu builder.fielddataFrequencyFilter(minFrequency, maxFrequency, minSegmentSize); DocumentMapperParser.checkNoRemainingFields(propName, frequencyFilter, parserContext.indexVersionCreated()); iterator.remove(); - } else if (parseMultiField(builder, fieldName, parserContext, propName, propNode)) { - iterator.remove(); } } return builder; diff --git a/core/src/main/java/org/elasticsearch/index/mapper/core/TypeParsers.java b/core/src/main/java/org/elasticsearch/index/mapper/core/TypeParsers.java index 012a72743b1..bc7c97bc4ff 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/core/TypeParsers.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/core/TypeParsers.java @@ -268,6 +268,8 @@ public class TypeParsers { && parserContext.indexVersionCreated().before(Version.V_5_0_0_alpha1)) { // ignore for bw compat iterator.remove(); + } else if (parseMultiField(builder, name, parserContext, propName, propNode)) { + iterator.remove(); } else if (propName.equals("copy_to")) { if (parserContext.isWithinMultiField()) { if (indexVersionCreated.after(Version.V_2_1_0) || diff --git a/core/src/main/java/org/elasticsearch/index/mapper/geo/BaseGeoPointFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/geo/BaseGeoPointFieldMapper.java index ae181b3c98c..fec0720ce70 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/geo/BaseGeoPointFieldMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/geo/BaseGeoPointFieldMapper.java @@ -220,8 +220,6 @@ public abstract class BaseGeoPointFieldMapper extends FieldMapper implements Arr } else if (propName.equals(Names.IGNORE_MALFORMED)) { builder.ignoreMalformed(XContentMapValues.lenientNodeBooleanValue(propNode)); iterator.remove(); - } else if (parseMultiField(builder, name, parserContext, propName, propNode)) { - iterator.remove(); } } diff --git a/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/ExternalMapper.java b/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/ExternalMapper.java index 8c25713ce3d..e1b94967b43 100755 --- a/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/ExternalMapper.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/ExternalMapper.java @@ -125,16 +125,6 @@ public class ExternalMapper extends FieldMapper { public Mapper.Builder parse(String name, Map node, ParserContext parserContext) throws MapperParsingException { ExternalMapper.Builder builder = new ExternalMapper.Builder(name, generatedValue, mapperName); parseField(builder, name, node, parserContext); - for (Iterator> iterator = node.entrySet().iterator(); iterator.hasNext();) { - Map.Entry entry = iterator.next(); - String propName = Strings.toUnderscoreCase(entry.getKey()); - Object propNode = entry.getValue(); - - if (parseMultiField(builder, name, parserContext, propName, propNode)) { - iterator.remove(); - } - } - return builder; } }