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.
This commit is contained in:
Nick Knize 2019-02-11 11:57:55 -06:00 committed by Nicholas Knize
parent d1848b96fc
commit 078da6d9bd
1 changed files with 7 additions and 3 deletions

View File

@ -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());
}