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
5 changes: 5 additions & 0 deletions docs/reference/mapping/types/geo-shape.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ and reject the whole document.
|`coerce` |If `true` unclosed linear rings in polygons will be automatically closed.
| `false`

|`doc_values` |Should the field be stored on disk in a column-stride fashion, so that it
can later be used for sorting, aggregations, or scripting? Accepts `true`
(default) or `false`.
| `true` for BKD-backed geo_shape, `false` for prefix tree indexing strategy

|=======================================================================


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,20 @@ public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext
XContentMapValues.nodeBooleanValue(fieldNode,
name + "." + GeoPointFieldMapper.Names.IGNORE_Z_VALUE.getPreferredName()));
iterator.remove();
} else if (TypeParsers.DOC_VALUES.equals(fieldName)) {
params.put(TypeParsers.DOC_VALUES, XContentMapValues.nodeBooleanValue(fieldNode, name + "." + TypeParsers.DOC_VALUES));
iterator.remove();
}
}
if (parsedDeprecatedParameters == false) {
params.remove(DEPRECATED_PARAMETERS_KEY);
}
Builder builder = newBuilder(name, params);

if (params.containsKey(TypeParsers.DOC_VALUES)) {
builder.docValues((Boolean) params.get(TypeParsers.DOC_VALUES));
}

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 @@ -197,6 +197,15 @@ public GeoShapeFieldType fieldType() {
return (GeoShapeFieldType)fieldType;
}

public Builder docValues(boolean hasDocValues) {
if (hasDocValues) {
throw new ElasticsearchParseException("geo_shape field [" + name
+ "] indexed using prefix-trees do not support doc_values");
}
// doc-values already set to `false`
return this;
}

private void setupFieldTypeDeprecatedParameters(BuilderContext context) {
GeoShapeFieldType ft = fieldType();
if (deprecatedParameters.strategy != null) {
Expand Down Expand Up @@ -318,6 +327,7 @@ public GeoShapeFieldType() {
setStored(false);
setStoreTermVectors(false);
setOmitNorms(true);
setHasDocValues(false);
}

protected GeoShapeFieldType(GeoShapeFieldType ref) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void testDefaultConfiguration() throws IOException {
GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
assertThat(geoShapeFieldMapper.fieldType().orientation(),
equalTo(GeoShapeFieldMapper.Defaults.ORIENTATION.value()));
assertTrue(geoShapeFieldMapper.fieldType.hasDocValues());
assertTrue(geoShapeFieldMapper.fieldType().hasDocValues());
}

/**
Expand Down Expand Up @@ -214,6 +214,41 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,42 @@ public void testPointsOnlyFalseWithTermStrategy() throws Exception {
assertFieldWarnings("tree", "precision", "strategy", "points_only");
}

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

ElasticsearchParseException e = expectThrows(ElasticsearchParseException.class,
() -> createIndex("test").mapperService().documentMapperParser().parse("type1", new CompressedXContent(trueMapping)));
assertThat(e.getMessage(), equalTo("geo_shape field [location] indexed using prefix-trees do not support doc_values"));

// explicit false doc_values
String falseMapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type1")
.startObject("properties").startObject("location")
.field("type", "geo_shape")
.field("tree", "quadtree")
.field("doc_values", "false")
.endObject().endObject()
.endObject().endObject());

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

assertFalse(((LegacyGeoShapeFieldMapper)fieldMapper).fieldType().hasDocValues());

assertFieldWarnings("tree");
talevy marked this conversation as resolved.
Show resolved Hide resolved
}

public String toXContentString(LegacyGeoShapeFieldMapper mapper, boolean includeDefaults) throws IOException {
XContentBuilder builder = XContentFactory.jsonBuilder().startObject();
ToXContent.Params params;
Expand Down