Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bcd7016

Browse files
committedSep 13, 2022
Solves #4002, ignoring all malformed objects when ignore_malformed is set to true;
Signed-off-by: Hauck <joaoh14@gmail.com>
1 parent 763a89f commit bcd7016

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed
 

‎server/src/main/java/org/opensearch/index/mapper/FieldMapper.java

+17-11
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
import com.carrotsearch.hppc.cursors.ObjectCursor;
3636
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
37+
3738
import org.apache.lucene.document.Field;
3839
import org.apache.lucene.document.FieldType;
3940
import org.apache.lucene.index.IndexOptions;
@@ -265,6 +266,7 @@ public boolean parsesArrayValue() {
265266
* Parse the field value using the provided {@link ParseContext}.
266267
*/
267268
public void parse(ParseContext context) throws IOException {
269+
boolean ignore_malformed = IGNORE_MALFORMED_SETTING.get(context.indexSettings().getSettings());
268270
try {
269271
parseCreateField(context);
270272
} catch (Exception e) {
@@ -278,23 +280,27 @@ public void parse(ParseContext context) throws IOException {
278280
valuePreview = complexValue.toString();
279281
}
280282
} catch (Exception innerException) {
283+
if (!ignore_malformed) {
284+
throw new MapperParsingException(
285+
"failed to parse field [{}] of type [{}] in document with id '{}'. " + "Could not parse field value preview,",
286+
e,
287+
fieldType().name(),
288+
fieldType().typeName(),
289+
context.sourceToParse().id()
290+
);
291+
}
292+
}
293+
294+
if (!ignore_malformed) {
281295
throw new MapperParsingException(
282-
"failed to parse field [{}] of type [{}] in document with id '{}'. " + "Could not parse field value preview,",
296+
"failed to parse field [{}] of type [{}] in document with id '{}'. " + "Preview of field's value: '{}'",
283297
e,
284298
fieldType().name(),
285299
fieldType().typeName(),
286-
context.sourceToParse().id()
300+
context.sourceToParse().id(),
301+
valuePreview
287302
);
288303
}
289-
290-
throw new MapperParsingException(
291-
"failed to parse field [{}] of type [{}] in document with id '{}'. " + "Preview of field's value: '{}'",
292-
e,
293-
fieldType().name(),
294-
fieldType().typeName(),
295-
context.sourceToParse().id(),
296-
valuePreview
297-
);
298304
}
299305
multiFields.parse(this, context);
300306
}

0 commit comments

Comments
 (0)
Please sign in to comment.