From 96cca039e95e38c24a5f8ddf25a5297176a8ec4e Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Mon, 30 Dec 2013 13:41:53 +0100 Subject: [PATCH] Honor `includeDefaults` in GeoPointFieldMapper. Close #4563 --- .../index/mapper/geo/GeoPointFieldMapper.java | 53 +++++++++++-------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/elasticsearch/index/mapper/geo/GeoPointFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/geo/GeoPointFieldMapper.java index df4d525d1ea..c2b20720b4e 100644 --- a/src/main/java/org/elasticsearch/index/mapper/geo/GeoPointFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/geo/GeoPointFieldMapper.java @@ -660,43 +660,50 @@ public class GeoPointFieldMapper extends AbstractFieldMapper implement @Override protected void doXContentBody(XContentBuilder builder, boolean includeDefaults, Params params) throws IOException { super.doXContentBody(builder, includeDefaults, params); - builder.field("type", CONTENT_TYPE); - if (pathType != Defaults.PATH_TYPE) { + if (includeDefaults || pathType != Defaults.PATH_TYPE) { builder.field("path", pathType.name().toLowerCase(Locale.ROOT)); } - if (enableLatLon != Defaults.ENABLE_LATLON) { + if (includeDefaults || enableLatLon != Defaults.ENABLE_LATLON) { builder.field("lat_lon", enableLatLon); } - if (enableGeoHash != Defaults.ENABLE_GEOHASH) { + if (includeDefaults || enableGeoHash != Defaults.ENABLE_GEOHASH) { builder.field("geohash", enableGeoHash); } - if (enableGeohashPrefix != Defaults.ENABLE_GEOHASH_PREFIX) { + if (includeDefaults || enableGeohashPrefix != Defaults.ENABLE_GEOHASH_PREFIX) { builder.field("geohash_prefix", enableGeohashPrefix); } - if (geoHashPrecision != Defaults.GEO_HASH_PRECISION) { + if (includeDefaults || geoHashPrecision != Defaults.GEO_HASH_PRECISION) { builder.field("geohash_precision", geoHashPrecision); } - if (precisionStep != null) { + if (includeDefaults || precisionStep != null) { builder.field("precision_step", precisionStep); } - if (!validateLat && !validateLon) { - builder.field("validate", false); - } else { - if (validateLat != Defaults.VALIDATE_LAT) { - builder.field("validate_lat", validateLat); - } - if (validateLon != Defaults.VALIDATE_LON) { - builder.field("validate_lon", validateLon); + if (includeDefaults || validateLat != Defaults.VALIDATE_LAT || validateLon != Defaults.VALIDATE_LON) { + if (validateLat && validateLon) { + builder.field("validate", true); + } else if (!validateLat && !validateLon) { + builder.field("validate", false); + } else { + if (includeDefaults || validateLat != Defaults.VALIDATE_LAT) { + builder.field("validate_lat", validateLat); + } + if (includeDefaults || validateLon != Defaults.VALIDATE_LON) { + builder.field("validate_lon", validateLon); + } } } - if (!normalizeLat && !normalizeLon) { - builder.field("normalize", false); - } else { - if (normalizeLat != Defaults.NORMALIZE_LAT) { - builder.field("normalize_lat", normalizeLat); - } - if (normalizeLon != Defaults.NORMALIZE_LON) { - builder.field("normalize_lon", normalizeLon); + if (includeDefaults || normalizeLat != Defaults.NORMALIZE_LAT || normalizeLon != Defaults.NORMALIZE_LON) { + if (normalizeLat && normalizeLon) { + builder.field("normalize", true); + } else if (!normalizeLat && !normalizeLon) { + builder.field("normalize", false); + } else { + if (includeDefaults || normalizeLat != Defaults.NORMALIZE_LAT) { + builder.field("normalize_lat", normalizeLat); + } + if (includeDefaults || normalizeLon != Defaults.NORMALIZE_LON) { + builder.field("normalize_lon", normalizeLat); + } } } }