Skip to content

Commit

Permalink
Legacy geo-shape mapper not detecting [points_only] parameter (#70765)
Browse files Browse the repository at this point in the history
We have two geo_shape mapper implementations, and the type parser
will select which one to use by examining the other fields used in the mapper
definition. This commit fixes a bug in the list of legacy parameters that was
causing a geo_shape mapper with only a points_only field to throw an
exception when parsed.

Fixes #70751
  • Loading branch information
romseygeek committed Mar 24, 2021
1 parent d69d6f7 commit 64c83c8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class LegacyGeoShapeFieldMapper extends AbstractShapeGeometryFieldMapper<
public static final String CONTENT_TYPE = "geo_shape";

public static final Set<String> DEPRECATED_PARAMETERS
= new HashSet<>(Arrays.asList("strategy", "tree", "tree_levels", "precision", "distance_error_pct", "points only"));
= new HashSet<>(Arrays.asList("strategy", "tree", "tree_levels", "precision", "distance_error_pct", "points_only"));

public static boolean containsDeprecatedParameter(Set<String> paramKeys) {
return DEPRECATED_PARAMETERS.stream().anyMatch(paramKeys::contains);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree;
import org.apache.lucene.spatial.prefix.tree.QuadPrefixTree;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.CheckedConsumer;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.collect.List;
import org.elasticsearch.common.geo.GeoUtils;
Expand All @@ -28,6 +29,8 @@

import java.io.IOException;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import static java.util.Collections.singletonMap;
import static org.hamcrest.Matchers.containsString;
Expand Down Expand Up @@ -95,6 +98,28 @@ protected boolean supportsMeta() {
return false;
}

public void testLegacySwitches() throws IOException {
// if one of the legacy parameters is added to a 'type':'geo_shape' config then
// that will select the legacy field mapper
testLegacySwitch("strategy", b -> b.field("strategy", "term"));
testLegacySwitch("tree", b -> b.field("tree", "geohash"));
testLegacySwitch("tree_levels", b -> b.field("tree_levels", 5));
testLegacySwitch("precision", b -> b.field("precision", 10));
testLegacySwitch("points_only", b -> b.field("points_only", true));
testLegacySwitch("distance_error_pct", b -> b.field("distance_error_pct", 0.8));
}

private void testLegacySwitch(String field, CheckedConsumer<XContentBuilder, IOException> config) throws IOException {
createDocumentMapper(fieldMapping(b -> {
b.field("type", "geo_shape");
config.accept(b);
}));
Set<String> warnings = new HashSet<>();
warnings.add(field);
warnings.add("strategy");
assertFieldWarnings(warnings.toArray(new String[0]));
}

public void testDefaultConfiguration() throws IOException {
XContentBuilder mapping = fieldMapping(this::minimalMapping);
DocumentMapper mapper = createDocumentMapper(mapping);
Expand Down

0 comments on commit 64c83c8

Please sign in to comment.