Skip to content

Commit 0844455

Browse files
authored
Add geo_shape mapper supporting doc-values in Spatial Plugin (#55037) (#55500)
After #53562, the `geo_shape` field mapper is registered within a module. This opens the door for introducing a new `geo_shape` field mapper into the Spatial Plugin that has doc-values support. This is very much an extension of server's GeoShapeFieldMapper, but with the addition of the doc values implementation.
1 parent 8d05d7d commit 0844455

File tree

41 files changed

+3880
-35
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+3880
-35
lines changed

distribution/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,12 @@ configure(subprojects.findAll { ['archives', 'packages'].contains(it.name) }) {
317317
excludePlatforms = []
318318
}
319319
from(buildModules) {
320+
// geo registers the geo_shape mapper that is overridden by
321+
// the geo_shape mapper registered in the x-pack-spatial plugin
322+
if (oss == false) {
323+
exclude "**/geo/**"
324+
}
325+
320326
for (String excludePlatform : excludePlatforms) {
321327
exclude "**/platform/${excludePlatform}/**"
322328
}

modules/geo/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ esplugin {
2121
description 'Placeholder plugin for geospatial features in ES. only registers geo_shape field mapper for now'
2222
classname 'org.elasticsearch.geo.GeoPlugin'
2323
}
24+
25+
artifacts {
26+
restTests(new File(projectDir, "src/test/resources/rest-api-spec/test"))
27+
}

modules/geo/src/main/java/org/elasticsearch/geo/GeoPlugin.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
package org.elasticsearch.geo;
2121

22-
import org.elasticsearch.index.mapper.AbstractGeometryFieldMapper;
2322
import org.elasticsearch.index.mapper.GeoShapeFieldMapper;
2423
import org.elasticsearch.index.mapper.Mapper;
2524
import org.elasticsearch.plugins.MapperPlugin;
@@ -32,6 +31,6 @@ public class GeoPlugin extends Plugin implements MapperPlugin {
3231

3332
@Override
3433
public Map<String, Mapper.TypeParser> getMappers() {
35-
return Collections.singletonMap(GeoShapeFieldMapper.CONTENT_TYPE, new AbstractGeometryFieldMapper.TypeParser());
34+
return Collections.singletonMap(GeoShapeFieldMapper.CONTENT_TYPE, new GeoShapeFieldMapper.TypeParser());
3635
}
3736
}

server/src/main/java/org/elasticsearch/common/io/stream/ByteBufferStreamInput.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ public long readLong() throws IOException {
110110
}
111111
}
112112

113+
public void position(int newPosition) throws IOException {
114+
buffer.position(newPosition);
115+
}
116+
117+
public int position() throws IOException {
118+
return buffer.position();
119+
}
120+
113121
@Override
114122
public void reset() throws IOException {
115123
buffer.reset();

server/src/main/java/org/elasticsearch/index/mapper/AbstractGeometryFieldMapper.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ protected void setupFieldType(BuilderContext context) {
185185

186186
protected static final String DEPRECATED_PARAMETERS_KEY = "deprecated_parameters";
187187

188-
public static class TypeParser implements Mapper.TypeParser {
188+
public abstract static class TypeParser implements Mapper.TypeParser {
189+
protected abstract Builder newBuilder(String name, Map<String, Object> params);
190+
189191
protected boolean parseXContentParameters(String name, Map.Entry<String, Object> entry, Map<String, Object> params)
190192
throws MapperParsingException {
191193
if (DeprecatedParameters.parse(name, entry.getKey(), entry.getValue(),
@@ -195,13 +197,6 @@ protected boolean parseXContentParameters(String name, Map.Entry<String, Object>
195197
return false;
196198
}
197199

198-
protected Builder newBuilder(String name, Map<String, Object> params) {
199-
if (params.containsKey(DEPRECATED_PARAMETERS_KEY)) {
200-
return new LegacyGeoShapeFieldMapper.Builder(name, (DeprecatedParameters)params.get(DEPRECATED_PARAMETERS_KEY));
201-
}
202-
return new GeoShapeFieldMapper.Builder(name);
203-
}
204-
205200
@Override
206201
public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
207202
Map<String, Object> params = new HashMap<>();

server/src/main/java/org/elasticsearch/index/mapper/GeoShapeFieldMapper.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import org.elasticsearch.geometry.Geometry;
2727
import org.elasticsearch.index.query.VectorGeoShapeQueryProcessor;
2828

29+
import java.util.Map;
30+
2931
/**
3032
* FieldMapper for indexing {@link LatLonShape}s.
3133
* <p>
@@ -76,7 +78,7 @@ protected void setupFieldType(BuilderContext context) {
7678
}
7779
}
7880

79-
public static final class GeoShapeFieldType extends AbstractGeometryFieldType<Geometry, Geometry> {
81+
public static class GeoShapeFieldType extends AbstractGeometryFieldType<Geometry, Geometry> {
8082
public GeoShapeFieldType() {
8183
super();
8284
}
@@ -96,6 +98,18 @@ public String typeName() {
9698
}
9799
}
98100

101+
public static final class TypeParser extends AbstractGeometryFieldMapper.TypeParser {
102+
103+
@Override
104+
protected AbstractGeometryFieldMapper.Builder newBuilder(String name, Map<String, Object> params) {
105+
if (params.containsKey(DEPRECATED_PARAMETERS_KEY)) {
106+
return new LegacyGeoShapeFieldMapper.Builder(name,
107+
(LegacyGeoShapeFieldMapper.DeprecatedParameters)params.get(DEPRECATED_PARAMETERS_KEY));
108+
}
109+
return new GeoShapeFieldMapper.Builder(name);
110+
}
111+
}
112+
99113
public GeoShapeFieldMapper(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType,
100114
Explicit<Boolean> ignoreMalformed, Explicit<Boolean> coerce,
101115
Explicit<Boolean> ignoreZValue, Settings indexSettings,

server/src/main/java/org/elasticsearch/index/mapper/GeoShapeIndexer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
/**
5050
* Utility class that converts geometries into Lucene-compatible form for indexing in a geo_shape field.
5151
*/
52-
public final class GeoShapeIndexer implements AbstractGeometryFieldMapper.Indexer<Geometry, Geometry> {
52+
public class GeoShapeIndexer implements AbstractGeometryFieldMapper.Indexer<Geometry, Geometry> {
5353

5454
private final boolean orientation;
5555
private final String name;

server/src/main/java/org/elasticsearch/search/aggregations/support/MissingValues.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public String toString() {
5757
};
5858
}
5959

60-
static SortedBinaryDocValues replaceMissing(final SortedBinaryDocValues values, final BytesRef missing) {
60+
public static SortedBinaryDocValues replaceMissing(final SortedBinaryDocValues values, final BytesRef missing) {
6161
return new SortedBinaryDocValues() {
6262

6363
private int count;

test/framework/src/main/java/org/elasticsearch/test/TestGeoShapeFieldMapperPlugin.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
package org.elasticsearch.test;
2020

21-
import org.elasticsearch.index.mapper.AbstractGeometryFieldMapper;
2221
import org.elasticsearch.index.mapper.GeoShapeFieldMapper;
2322
import org.elasticsearch.index.mapper.Mapper;
2423
import org.elasticsearch.plugins.MapperPlugin;
@@ -40,7 +39,7 @@ public class TestGeoShapeFieldMapperPlugin extends Plugin implements MapperPlugi
4039
@Override
4140
public Map<String, Mapper.TypeParser> getMappers() {
4241
Map<String, Mapper.TypeParser> mappers = new LinkedHashMap<>();
43-
mappers.put(GeoShapeFieldMapper.CONTENT_TYPE, new AbstractGeometryFieldMapper.TypeParser());
42+
mappers.put(GeoShapeFieldMapper.CONTENT_TYPE, new GeoShapeFieldMapper.TypeParser());
4443
return Collections.unmodifiableMap(mappers);
4544
}
4645
}

x-pack/plugin/spatial/build.gradle

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,24 @@ esplugin {
1212
dependencies {
1313
compileOnly project(path: xpackModule('core'), configuration: 'default')
1414
testCompile project(path: xpackModule('core'), configuration: 'testArtifacts')
15-
testCompile project(path: ':modules:geo', configuration: 'runtime')
15+
compile project(path: ':modules:geo', configuration: 'default')
16+
restTestConfig project(path: ':modules:geo', configuration: 'restTests')
17+
}
18+
19+
restResources {
20+
restApi {
21+
includeCore '_common', 'indices', 'index', 'search'
22+
}
23+
restTests {
24+
includeCore 'geo_shape'
25+
}
26+
}
27+
28+
testClusters.integTest {
29+
testDistribution = 'DEFAULT'
1630
}
1731

1832
licenseHeaders {
1933
// This class was sourced from apache lucene's sandbox module tests
2034
excludes << 'org/apache/lucene/geo/XShapeTestUtil.java'
2135
}
22-
23-
// xpack modules are installed in real clusters as the meta plugin, so
24-
// installing them as individual plugins for integ tests doesn't make sense,
25-
// so we disable integ tests
26-
integTest.enabled = false

0 commit comments

Comments
 (0)