99
1010package org .elasticsearch .index .mapper ;
1111
12+ import org .apache .logging .log4j .Logger ;
1213import org .elasticsearch .common .compress .CompressedXContent ;
14+ import org .elasticsearch .common .logging .Loggers ;
1315import org .elasticsearch .features .NodeFeature ;
1416import org .elasticsearch .index .IndexSettings ;
1517import org .elasticsearch .index .IndexSortConfig ;
@@ -25,6 +27,7 @@ public class DocumentMapper {
2527 private final DocumentParser documentParser ;
2628 private final MapperMetrics mapperMetrics ;
2729 private final IndexVersion indexVersion ;
30+ private final Logger logger ;
2831
2932 static final NodeFeature INDEX_SORTING_ON_NESTED = new NodeFeature ("mapper.index_sorting_on_nested" );
3033
@@ -44,7 +47,8 @@ public static DocumentMapper createEmpty(MapperService mapperService) {
4447 mapping ,
4548 mapping .toCompressedXContent (),
4649 IndexVersion .current (),
47- mapperService .getMapperMetrics ()
50+ mapperService .getMapperMetrics (),
51+ mapperService .index ().getName ()
4852 );
4953 }
5054
@@ -53,19 +57,27 @@ public static DocumentMapper createEmpty(MapperService mapperService) {
5357 Mapping mapping ,
5458 CompressedXContent source ,
5559 IndexVersion version ,
56- MapperMetrics mapperMetrics
60+ MapperMetrics mapperMetrics ,
61+ String indexName
5762 ) {
5863 this .documentParser = documentParser ;
5964 this .type = mapping .getRoot ().fullPath ();
6065 this .mappingLookup = MappingLookup .fromMapping (mapping );
6166 this .mappingSource = source ;
6267 this .mapperMetrics = mapperMetrics ;
6368 this .indexVersion = version ;
69+ this .logger = Loggers .getLogger (getClass (), indexName );
6470
6571 assert mapping .toCompressedXContent ().equals (source ) || isSyntheticSourceMalformed (source , version )
6672 : "provided source [" + source + "] differs from mapping [" + mapping .toCompressedXContent () + "]" ;
6773 }
6874
75+ private void maybeLogDebug (Exception ex ) {
76+ if (logger .isDebugEnabled ()) {
77+ logger .debug ("Error while parsing document: " + ex .getMessage (), ex );
78+ }
79+ }
80+
6981 /**
7082 * Indexes built at v.8.7 were missing an explicit entry for synthetic_source.
7183 * This got restored in v.8.10 to avoid confusion. The change is only restricted to mapping printout, it has no
@@ -110,7 +122,12 @@ public MappingLookup mappers() {
110122 }
111123
112124 public ParsedDocument parse (SourceToParse source ) throws DocumentParsingException {
113- return documentParser .parseDocument (source , mappingLookup );
125+ try {
126+ return documentParser .parseDocument (source , mappingLookup );
127+ } catch (Exception e ) {
128+ maybeLogDebug (e );
129+ throw e ;
130+ }
114131 }
115132
116133 public void validate (IndexSettings settings , boolean checkLimits ) {
0 commit comments