|
@@ -42,6 +42,7 @@ import static org.elasticsearch.index.mapper.GeoPointFieldMapper.Names.IGNORE_Z_
|
|
|
import static org.hamcrest.Matchers.containsString;
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
import static org.hamcrest.Matchers.instanceOf;
|
|
|
+import static org.hamcrest.Matchers.not;
|
|
|
|
|
|
public class GeoShapeFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
|
|
@@ -588,10 +589,65 @@ public class GeoShapeFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public String toXContentString(GeoShapeFieldMapper mapper) throws IOException {
|
|
|
+ public void testPointsOnlyDefaultsWithTermStrategy() throws IOException {
|
|
|
+ String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type1")
|
|
|
+ .startObject("properties").startObject("location")
|
|
|
+ .field("type", "geo_shape")
|
|
|
+ .field("tree", "quadtree")
|
|
|
+ .field("precision", "10m")
|
|
|
+ .field("strategy", "term")
|
|
|
+ .endObject().endObject()
|
|
|
+ .endObject().endObject());
|
|
|
+
|
|
|
+ DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1", new CompressedXContent(mapping));
|
|
|
+ FieldMapper fieldMapper = defaultMapper.mappers().getMapper("location");
|
|
|
+ assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));
|
|
|
+
|
|
|
+ GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
|
|
|
+ PrefixTreeStrategy strategy = geoShapeFieldMapper.fieldType().defaultStrategy();
|
|
|
+
|
|
|
+ assertThat(strategy.getDistErrPct(), equalTo(0.0));
|
|
|
+ assertThat(strategy.getGrid(), instanceOf(QuadPrefixTree.class));
|
|
|
+ assertThat(strategy.getGrid().getMaxLevels(), equalTo(23));
|
|
|
+ assertThat(strategy.isPointsOnly(), equalTo(true));
|
|
|
+ // term strategy changes the default for points_only, check that we handle it correctly
|
|
|
+ assertThat(toXContentString(geoShapeFieldMapper, false), not(containsString("points_only")));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void testPointsOnlyFalseWithTermStrategy() throws Exception {
|
|
|
+ String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type1")
|
|
|
+ .startObject("properties").startObject("location")
|
|
|
+ .field("type", "geo_shape")
|
|
|
+ .field("tree", "quadtree")
|
|
|
+ .field("precision", "10m")
|
|
|
+ .field("strategy", "term")
|
|
|
+ .field("points_only", false)
|
|
|
+ .endObject().endObject()
|
|
|
+ .endObject().endObject());
|
|
|
+
|
|
|
+ DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
|
|
|
+
|
|
|
+ IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
|
|
|
+ () -> parser.parse("type1", new CompressedXContent(mapping))
|
|
|
+ );
|
|
|
+ assertThat(e.getMessage(), containsString("points_only cannot be set to false for term strategy"));
|
|
|
+ }
|
|
|
+
|
|
|
+ public String toXContentString(GeoShapeFieldMapper mapper, boolean includeDefaults) throws IOException {
|
|
|
XContentBuilder builder = XContentFactory.jsonBuilder().startObject();
|
|
|
- mapper.doXContentBody(builder, true, new ToXContent.MapParams(Collections.singletonMap("include_defaults", "true")));
|
|
|
+ ToXContent.Params params;
|
|
|
+ if (includeDefaults) {
|
|
|
+ params = new ToXContent.MapParams(Collections.singletonMap("include_defaults", "true"));
|
|
|
+ } else {
|
|
|
+ params = ToXContent.EMPTY_PARAMS;
|
|
|
+ }
|
|
|
+ mapper.doXContentBody(builder, includeDefaults, params);
|
|
|
return Strings.toString(builder.endObject());
|
|
|
}
|
|
|
|
|
|
+ public String toXContentString(GeoShapeFieldMapper mapper) throws IOException {
|
|
|
+ return toXContentString(mapper, true);
|
|
|
+ }
|
|
|
+
|
|
|
}
|