Browse Source

Revert "enhancement: boolean field to support ignore_malformed (#90122)"

This was merged in error without a full CI run, and has some issues.

This reverts commit edcdc43519c7f6789b4c5300011b522d13d829cd.
This reverts commit 26c0a35558edb5de1b7fd51a725de613939da7af.
David Turner 2 years ago
parent
commit
ce736dd0e0

+ 0 - 1
docs/reference/mapping/params/ignore-malformed.asciidoc

@@ -49,7 +49,6 @@ PUT my-index-000001/_doc/2
 The `ignore_malformed` setting is currently supported by the following <<mapping-types,mapping types>>:
 The `ignore_malformed` setting is currently supported by the following <<mapping-types,mapping types>>:
 
 
 <<number>>::         `long`, `integer`, `short`, `byte`, `double`, `float`, `half_float`, `scaled_float`
 <<number>>::         `long`, `integer`, `short`, `byte`, `double`, `float`, `half_float`, `scaled_float`
-<<boolean>>::        `true`, `false`
 <<date>>::           `date`
 <<date>>::           `date`
 <<date_nanos>>::     `date_nanos`
 <<date_nanos>>::     `date_nanos`
 <<geo-point>>::     `geo_point` for lat/lon points
 <<geo-point>>::     `geo_point` for lat/lon points

+ 0 - 4
docs/reference/mapping/types/boolean.asciidoc

@@ -179,10 +179,6 @@ The following parameters are accepted by `boolean` fields:
     enabled can still be queried using term or range-based queries,
     enabled can still be queried using term or range-based queries,
     albeit slower.
     albeit slower.
 
 
-<<ignore-malformed, `ignore_malformed`>>::
-
-    Trying to index the wrong data type into a field throws an exception by default, and rejects the whole document. If this parameter is set to true, it allows the exception to be ignored. The malformed field is not indexed, but other fields in the document are processed normally. Accepts `true` or `false`.
-
 <<null-value,`null_value`>>::
 <<null-value,`null_value`>>::
 
 
     Accepts any of the true or false values listed above. The value is
     Accepts any of the true or false values listed above. The value is

+ 7 - 26
server/src/main/java/org/elasticsearch/index/mapper/BooleanFieldMapper.java

@@ -22,7 +22,6 @@ import org.apache.lucene.search.Query;
 import org.apache.lucene.search.TermRangeQuery;
 import org.apache.lucene.search.TermRangeQuery;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.BytesRef;
 import org.elasticsearch.Version;
 import org.elasticsearch.Version;
-import org.elasticsearch.common.Explicit;
 import org.elasticsearch.common.lucene.Lucene;
 import org.elasticsearch.common.lucene.Lucene;
 import org.elasticsearch.common.xcontent.support.XContentMapValues;
 import org.elasticsearch.common.xcontent.support.XContentMapValues;
 import org.elasticsearch.core.Booleans;
 import org.elasticsearch.core.Booleans;
@@ -85,7 +84,7 @@ public class BooleanFieldMapper extends FieldMapper {
         private final Parameter<Boolean> docValues = Parameter.docValuesParam(m -> toType(m).hasDocValues, true);
         private final Parameter<Boolean> docValues = Parameter.docValuesParam(m -> toType(m).hasDocValues, true);
         private final Parameter<Boolean> indexed = Parameter.indexParam(m -> toType(m).indexed, true);
         private final Parameter<Boolean> indexed = Parameter.indexParam(m -> toType(m).indexed, true);
         private final Parameter<Boolean> stored = Parameter.storeParam(m -> toType(m).stored, false);
         private final Parameter<Boolean> stored = Parameter.storeParam(m -> toType(m).stored, false);
-        private final Parameter<Explicit<Boolean>> ignoreMalformed;
+
         private final Parameter<Boolean> nullValue = new Parameter<>(
         private final Parameter<Boolean> nullValue = new Parameter<>(
             "null_value",
             "null_value",
             false,
             false,
@@ -105,23 +104,17 @@ public class BooleanFieldMapper extends FieldMapper {
 
 
         private final Version indexCreatedVersion;
         private final Version indexCreatedVersion;
 
 
-        public Builder(String name, ScriptCompiler scriptCompiler, boolean ignoreMalformedByDefault, Version indexCreatedVersion) {
+        public Builder(String name, ScriptCompiler scriptCompiler, Version indexCreatedVersion) {
             super(name);
             super(name);
             this.scriptCompiler = Objects.requireNonNull(scriptCompiler);
             this.scriptCompiler = Objects.requireNonNull(scriptCompiler);
             this.indexCreatedVersion = Objects.requireNonNull(indexCreatedVersion);
             this.indexCreatedVersion = Objects.requireNonNull(indexCreatedVersion);
-            this.ignoreMalformed = Parameter.explicitBoolParam(
-                "ignore_malformed",
-                true,
-                m -> toType(m).ignoreMalformed,
-                ignoreMalformedByDefault
-            );
-            this.script.precludesParameters(ignoreMalformed, nullValue);
+            this.script.precludesParameters(nullValue);
             addScriptValidation(script, indexed, docValues);
             addScriptValidation(script, indexed, docValues);
         }
         }
 
 
         @Override
         @Override
         protected Parameter<?>[] getParameters() {
         protected Parameter<?>[] getParameters() {
-            return new Parameter<?>[] { meta, docValues, indexed, nullValue, stored, script, onScriptError, ignoreMalformed };
+            return new Parameter<?>[] { meta, docValues, indexed, nullValue, stored, script, onScriptError };
         }
         }
 
 
         @Override
         @Override
@@ -155,7 +148,7 @@ public class BooleanFieldMapper extends FieldMapper {
     private static final Version MINIMUM_COMPATIBILITY_VERSION = Version.fromString("5.0.0");
     private static final Version MINIMUM_COMPATIBILITY_VERSION = Version.fromString("5.0.0");
 
 
     public static final TypeParser PARSER = new TypeParser(
     public static final TypeParser PARSER = new TypeParser(
-        (n, c) -> new Builder(n, c.scriptCompiler(), IGNORE_MALFORMED_SETTING.get(c.getSettings()), c.indexVersionCreated()),
+        (n, c) -> new Builder(n, c.scriptCompiler(), c.indexVersionCreated()),
         MINIMUM_COMPATIBILITY_VERSION
         MINIMUM_COMPATIBILITY_VERSION
     );
     );
 
 
@@ -374,8 +367,6 @@ public class BooleanFieldMapper extends FieldMapper {
     private final FieldValues<Boolean> scriptValues;
     private final FieldValues<Boolean> scriptValues;
     private final ScriptCompiler scriptCompiler;
     private final ScriptCompiler scriptCompiler;
     private final Version indexCreatedVersion;
     private final Version indexCreatedVersion;
-    private final Explicit<Boolean> ignoreMalformed;
-    private final boolean ignoreMalformedByDefault;
 
 
     protected BooleanFieldMapper(
     protected BooleanFieldMapper(
         String simpleName,
         String simpleName,
@@ -393,8 +384,6 @@ public class BooleanFieldMapper extends FieldMapper {
         this.scriptValues = builder.scriptValues();
         this.scriptValues = builder.scriptValues();
         this.scriptCompiler = builder.scriptCompiler;
         this.scriptCompiler = builder.scriptCompiler;
         this.indexCreatedVersion = builder.indexCreatedVersion;
         this.indexCreatedVersion = builder.indexCreatedVersion;
-        this.ignoreMalformed = builder.ignoreMalformed.getValue();
-        this.ignoreMalformedByDefault = builder.ignoreMalformed.getDefaultValue().value();
     }
     }
 
 
     @Override
     @Override
@@ -420,15 +409,7 @@ public class BooleanFieldMapper extends FieldMapper {
                 value = nullValue;
                 value = nullValue;
             }
             }
         } else {
         } else {
-            try {
-                value = context.parser().booleanValue();
-            } catch (IllegalArgumentException e) {
-                if (ignoreMalformed.value() && context.parser().currentToken().isValue()) {
-                    context.addIgnoredField(mappedFieldType.name());
-                } else {
-                    throw e;
-                }
-            }
+            value = context.parser().booleanValue();
         }
         }
         indexValue(context, value);
         indexValue(context, value);
     }
     }
@@ -462,7 +443,7 @@ public class BooleanFieldMapper extends FieldMapper {
 
 
     @Override
     @Override
     public FieldMapper.Builder getMergeBuilder() {
     public FieldMapper.Builder getMergeBuilder() {
-        return new Builder(simpleName(), scriptCompiler, ignoreMalformedByDefault, indexCreatedVersion).init(this);
+        return new Builder(simpleName(), scriptCompiler, indexCreatedVersion).init(this);
     }
     }
 
 
     @Override
     @Override

+ 1 - 8
server/src/main/java/org/elasticsearch/index/mapper/DynamicFieldsBuilder.java

@@ -355,15 +355,8 @@ final class DynamicFieldsBuilder {
 
 
         @Override
         @Override
         public void newDynamicBooleanField(DocumentParserContext context, String name) throws IOException {
         public void newDynamicBooleanField(DocumentParserContext context, String name) throws IOException {
-            Settings settings = context.indexSettings().getSettings();
-            boolean ignoreMalformed = FieldMapper.IGNORE_MALFORMED_SETTING.get(settings);
             createDynamicField(
             createDynamicField(
-                new BooleanFieldMapper.Builder(
-                    name,
-                    ScriptCompiler.NONE,
-                    ignoreMalformed,
-                    context.indexSettings().getIndexVersionCreated()
-                ),
+                new BooleanFieldMapper.Builder(name, ScriptCompiler.NONE, context.indexSettings().getIndexVersionCreated()),
                 context
                 context
             );
             );
         }
         }

+ 1 - 1
server/src/test/java/org/elasticsearch/index/mapper/BooleanScriptFieldTypeTests.java

@@ -319,7 +319,7 @@ public class BooleanScriptFieldTypeTests extends AbstractNonTextScriptFieldTypeT
     }
     }
 
 
     public void testDualingQueries() throws IOException {
     public void testDualingQueries() throws IOException {
-        BooleanFieldMapper ootb = new BooleanFieldMapper.Builder("foo", ScriptCompiler.NONE,false, Version.CURRENT).build(
+        BooleanFieldMapper ootb = new BooleanFieldMapper.Builder("foo", ScriptCompiler.NONE, Version.CURRENT).build(
             MapperBuilderContext.root(false)
             MapperBuilderContext.root(false)
         );
         );
         try (Directory directory = newDirectory(); RandomIndexWriter iw = new RandomIndexWriter(random(), directory)) {
         try (Directory directory = newDirectory(); RandomIndexWriter iw = new RandomIndexWriter(random(), directory)) {

+ 1 - 3
server/src/test/java/org/elasticsearch/index/mapper/FieldAliasMapperValidationTests.java

@@ -158,9 +158,7 @@ public class FieldAliasMapperValidationTests extends ESTestCase {
     }
     }
 
 
     private static FieldMapper createFieldMapper(String parent, String name) {
     private static FieldMapper createFieldMapper(String parent, String name) {
-        return new BooleanFieldMapper.Builder(name, ScriptCompiler.NONE, false, Version.CURRENT).build(
-            new MapperBuilderContext(parent, false)
-        );
+        return new BooleanFieldMapper.Builder(name, ScriptCompiler.NONE, Version.CURRENT).build(new MapperBuilderContext(parent, false));
     }
     }
 
 
     private static ObjectMapper createObjectMapper(String name) {
     private static ObjectMapper createObjectMapper(String name) {

+ 1 - 1
server/src/test/java/org/elasticsearch/index/mapper/MultiFieldsSerializationTests.java

@@ -40,7 +40,7 @@ public class MultiFieldsSerializationTests extends ESTestCase {
             builder.add(new BooleanFieldMapper.Builder(name, ScriptCompiler.NONE, Version.CURRENT));
             builder.add(new BooleanFieldMapper.Builder(name, ScriptCompiler.NONE, Version.CURRENT));
         }
         }
 
 
-        Mapper.Builder root = new BooleanFieldMapper.Builder("root", ScriptCompiler.NONE, false, Version.CURRENT);
+        Mapper.Builder root = new BooleanFieldMapper.Builder("root", ScriptCompiler.NONE, Version.CURRENT);
         FieldMapper.MultiFields multiFields = builder.build(root, MapperBuilderContext.root(false));
         FieldMapper.MultiFields multiFields = builder.build(root, MapperBuilderContext.root(false));
 
 
         String serialized = Strings.toString(multiFields);
         String serialized = Strings.toString(multiFields);