From 078da6d9bdf3605db831fbcd4b470b501003cdde Mon Sep 17 00:00:00 2001 From: Nick Knize Date: Mon, 11 Feb 2019 11:57:55 -0600 Subject: [PATCH] Fix GeoHash PrefixTree BWC (#38584) geo_shape indexes created before 6.6 use geohash string encoding as default tree parameter and quadtree encoding for 6.6 and later. This commit fixes bwc to use geohash encoding in LegacyGeoshapeFieldMapper for indexes created before 6.6. --- .../index/mapper/LegacyGeoShapeFieldMapper.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/index/mapper/LegacyGeoShapeFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/LegacyGeoShapeFieldMapper.java index c0b931225b8..9c8726a498a 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/LegacyGeoShapeFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/LegacyGeoShapeFieldMapper.java @@ -201,13 +201,15 @@ public class LegacyGeoShapeFieldMapper extends BaseGeoShapeFieldMapper { return (GeoShapeFieldType)fieldType; } - private void setupFieldTypeDeprecatedParameters() { + private void setupFieldTypeDeprecatedParameters(BuilderContext context) { GeoShapeFieldType ft = fieldType(); if (deprecatedParameters.strategy != null) { ft.setStrategy(deprecatedParameters.strategy); } if (deprecatedParameters.tree != null) { ft.setTree(deprecatedParameters.tree); + } else if (context.indexCreatedVersion().before(Version.V_6_6_0)) { + ft.setTree(DeprecatedParameters.PrefixTrees.GEOHASH); } if (deprecatedParameters.treeLevels != null) { ft.setTreeLevels(deprecatedParameters.treeLevels); @@ -275,7 +277,7 @@ public class LegacyGeoShapeFieldMapper extends BaseGeoShapeFieldMapper { } // setup the deprecated parameters and the prefix tree configuration - setupFieldTypeDeprecatedParameters(); + setupFieldTypeDeprecatedParameters(context); setupPrefixTrees(); } @@ -524,7 +526,9 @@ public class LegacyGeoShapeFieldMapper extends BaseGeoShapeFieldMapper { protected void doXContentBody(XContentBuilder builder, boolean includeDefaults, Params params) throws IOException { super.doXContentBody(builder, includeDefaults, params); - if (includeDefaults || fieldType().tree().equals(DeprecatedParameters.Defaults.TREE) == false) { + if (includeDefaults + || (fieldType().tree().equals(indexCreatedVersion.onOrAfter(Version.V_6_6_0) ? + DeprecatedParameters.Defaults.TREE : DeprecatedParameters.PrefixTrees.GEOHASH)) == false) { builder.field(DeprecatedParameters.Names.TREE.getPreferredName(), fieldType().tree()); }