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