Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add doc_values mapping option to geo_shape field mapping #47519

Merged
merged 11 commits into from
Feb 24, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext
}
Builder builder = newBuilder(name, params);

TypeParsers.parseField(builder, name, node, parserContext);

if (params.containsKey(Names.COERCE.getPreferredName())) {
builder.coerce((Boolean)params.get(Names.COERCE.getPreferredName()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public void testDefaultConfiguration() throws IOException {
GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
assertThat(geoShapeFieldMapper.fieldType().orientation(),
equalTo(GeoShapeFieldMapper.Defaults.ORIENTATION.value()));
assertTrue(geoShapeFieldMapper.fieldType().hasDocValues());
}

/**
Expand Down Expand Up @@ -213,6 +214,42 @@ public void testIgnoreMalformedParsing() throws IOException {
assertThat(ignoreMalformed.value(), equalTo(false));
}

/**
* Test that doc_values parameter correctly parses
*/
public void testDocValues() throws IOException {
String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type1")
.startObject("properties").startObject("location")
.field("type", "geo_shape")
.field("doc_values", true)
.endObject().endObject()
.endObject().endObject());

DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser()
.parse("type1", new CompressedXContent(mapping));
Mapper fieldMapper = defaultMapper.mappers().getMapper("location");
assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

boolean hasDocValues = ((GeoShapeFieldMapper)fieldMapper).fieldType().hasDocValues();
assertTrue(hasDocValues);

// explicit false accept_z_value test
talevy marked this conversation as resolved.
Show resolved Hide resolved
mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type1")
.startObject("properties").startObject("location")
.field("type", "geo_shape")
.field("doc_values", "false")
.endObject().endObject()
.endObject().endObject());

defaultMapper = createIndex("test2").mapperService().documentMapperParser()
.parse("type1", new CompressedXContent(mapping));
fieldMapper = defaultMapper.mappers().getMapper("location");
assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

hasDocValues = ((GeoShapeFieldMapper)fieldMapper).fieldType().hasDocValues();
assertFalse(hasDocValues);
}


private void assertFieldWarnings(String... fieldNames) {
String[] warnings = new String[fieldNames.length];
Expand Down