@@ -299,14 +299,7 @@ public Mapper parse(ParseContext context) throws IOException {
299
299
if (token == XContentParser .Token .START_ARRAY ) {
300
300
// its an array of array of lon/lat [ [1.2, 1.3], [1.4, 1.5] ]
301
301
while (token != XContentParser .Token .END_ARRAY ) {
302
- try {
303
- parse (context , GeoUtils .parseGeoPoint (context .parser (), sparse ));
304
- } catch (ElasticsearchParseException e ) {
305
- if (ignoreMalformed .value () == false ) {
306
- throw e ;
307
- }
308
- context .addIgnoredField (fieldType .name ());
309
- }
302
+ parseGeoPointIgnoringMalformed (context , sparse );
310
303
token = context .parser ().nextToken ();
311
304
}
312
305
} else {
@@ -326,42 +319,57 @@ public Mapper parse(ParseContext context) throws IOException {
326
319
} else {
327
320
while (token != XContentParser .Token .END_ARRAY ) {
328
321
if (token == XContentParser .Token .VALUE_STRING ) {
329
- parse (context , sparse . resetFromString ( context . parser (). text (), ignoreZValue . value ()) );
322
+ parseGeoPointStringIgnoringMalformed (context , sparse );
330
323
} else {
331
- try {
332
- parse (context , GeoUtils .parseGeoPoint (context .parser (), sparse ));
333
- } catch (ElasticsearchParseException e ) {
334
- if (ignoreMalformed .value () == false ) {
335
- throw e ;
336
- }
337
- }
324
+ parseGeoPointIgnoringMalformed (context , sparse );
338
325
}
339
326
token = context .parser ().nextToken ();
340
327
}
341
328
}
342
329
}
343
330
} else if (token == XContentParser .Token .VALUE_STRING ) {
344
- parse (context , sparse . resetFromString ( context . parser (). text (), ignoreZValue . value ()) );
331
+ parseGeoPointStringIgnoringMalformed (context , sparse );
345
332
} else if (token == XContentParser .Token .VALUE_NULL ) {
346
333
if (fieldType .nullValue () != null ) {
347
334
parse (context , (GeoPoint ) fieldType .nullValue ());
348
335
}
349
336
} else {
350
- try {
351
- parse (context , GeoUtils .parseGeoPoint (context .parser (), sparse ));
352
- } catch (ElasticsearchParseException e ) {
353
- if (ignoreMalformed .value () == false ) {
354
- throw e ;
355
- }
356
- context .addIgnoredField (fieldType .name ());
357
- }
337
+ parseGeoPointIgnoringMalformed (context , sparse );
358
338
}
359
339
}
360
340
361
341
context .path ().remove ();
362
342
return null ;
363
343
}
364
344
345
+ /**
346
+ * Parses geopoint represented as an object or an array, ignores malformed geopoints if needed
347
+ */
348
+ private void parseGeoPointIgnoringMalformed (ParseContext context , GeoPoint sparse ) throws IOException {
349
+ try {
350
+ parse (context , GeoUtils .parseGeoPoint (context .parser (), sparse ));
351
+ } catch (ElasticsearchParseException e ) {
352
+ if (ignoreMalformed .value () == false ) {
353
+ throw e ;
354
+ }
355
+ context .addIgnoredField (fieldType .name ());
356
+ }
357
+ }
358
+
359
+ /**
360
+ * Parses geopoint represented as a string and ignores malformed geopoints if needed
361
+ */
362
+ private void parseGeoPointStringIgnoringMalformed (ParseContext context , GeoPoint sparse ) throws IOException {
363
+ try {
364
+ parse (context , sparse .resetFromString (context .parser ().text (), ignoreZValue .value ()));
365
+ } catch (ElasticsearchParseException e ) {
366
+ if (ignoreMalformed .value () == false ) {
367
+ throw e ;
368
+ }
369
+ context .addIgnoredField (fieldType .name ());
370
+ }
371
+ }
372
+
365
373
@ Override
366
374
protected void doXContentBody (XContentBuilder builder , boolean includeDefaults , Params params ) throws IOException {
367
375
super .doXContentBody (builder , includeDefaults , params );
0 commit comments