Skip to content

Commit

Permalink
Solves #4002, ignoring all malformed objects when ignore_malformed is…
Browse files Browse the repository at this point in the history
… set to true;

Signed-off-by: Hauck <joaoh14@gmail.com>
  • Loading branch information
hauck-jvsh committed Sep 13, 2022
1 parent 763a89f commit bcd7016
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions server/src/main/java/org/opensearch/index/mapper/FieldMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import com.carrotsearch.hppc.cursors.ObjectCursor;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;

import org.apache.lucene.document.Field;
import org.apache.lucene.document.FieldType;
import org.apache.lucene.index.IndexOptions;
Expand Down Expand Up @@ -265,6 +266,7 @@ public boolean parsesArrayValue() {
* Parse the field value using the provided {@link ParseContext}.
*/
public void parse(ParseContext context) throws IOException {
boolean ignore_malformed = IGNORE_MALFORMED_SETTING.get(context.indexSettings().getSettings());
try {
parseCreateField(context);
} catch (Exception e) {
Expand All @@ -278,23 +280,27 @@ public void parse(ParseContext context) throws IOException {
valuePreview = complexValue.toString();
}
} catch (Exception innerException) {
if (!ignore_malformed) {
throw new MapperParsingException(
"failed to parse field [{}] of type [{}] in document with id '{}'. " + "Could not parse field value preview,",
e,
fieldType().name(),
fieldType().typeName(),
context.sourceToParse().id()
);
}
}

if (!ignore_malformed) {
throw new MapperParsingException(
"failed to parse field [{}] of type [{}] in document with id '{}'. " + "Could not parse field value preview,",
"failed to parse field [{}] of type [{}] in document with id '{}'. " + "Preview of field's value: '{}'",
e,
fieldType().name(),
fieldType().typeName(),
context.sourceToParse().id()
context.sourceToParse().id(),
valuePreview
);
}

throw new MapperParsingException(
"failed to parse field [{}] of type [{}] in document with id '{}'. " + "Preview of field's value: '{}'",
e,
fieldType().name(),
fieldType().typeName(),
context.sourceToParse().id(),
valuePreview
);
}
multiFields.parse(this, context);
}
Expand Down

0 comments on commit bcd7016

Please sign in to comment.