Skip to content

Commit 254d1e3

Browse files
talevynknize
andauthored
[7.x] Create new geo module and migrate geo_shape registration (#53562) (#54924)
This commit introduces a new `geo` module that is intended to be contain all the geo-spatial-specific features in server. As a first step, the responsibility of registering the geo_shape field mapper is moved to this module. Co-authored-by: Nicholas Knize <[email protected]>
1 parent 619028c commit 254d1e3

File tree

32 files changed

+336
-108
lines changed

32 files changed

+336
-108
lines changed

modules/geo/build.gradle

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
esplugin {
21+
description 'Placeholder plugin for geospatial features in ES. only registers geo_shape field mapper for now'
22+
classname 'org.elasticsearch.geo.GeoPlugin'
23+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.geo;
21+
22+
import org.elasticsearch.index.mapper.AbstractGeometryFieldMapper;
23+
import org.elasticsearch.index.mapper.GeoShapeFieldMapper;
24+
import org.elasticsearch.index.mapper.Mapper;
25+
import org.elasticsearch.plugins.MapperPlugin;
26+
import org.elasticsearch.plugins.Plugin;
27+
28+
import java.util.Collections;
29+
import java.util.Map;
30+
31+
public class GeoPlugin extends Plugin implements MapperPlugin {
32+
33+
@Override
34+
public Map<String, Mapper.TypeParser> getMappers() {
35+
return Collections.singletonMap(GeoShapeFieldMapper.CONTENT_TYPE, new AbstractGeometryFieldMapper.TypeParser());
36+
}
37+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.geo;
21+
22+
import com.carrotsearch.randomizedtesting.annotations.Name;
23+
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
24+
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate;
25+
import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase;
26+
27+
/** Runs yaml rest tests */
28+
public class GeoClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase {
29+
30+
public GeoClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) {
31+
super(testCandidate);
32+
}
33+
34+
@ParametersFactory
35+
public static Iterable<Object[]> parameters() throws Exception {
36+
return ESClientYamlSuiteTestCase.createParameters();
37+
}
38+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.elasticsearch.geo;
20+
21+
import org.elasticsearch.test.ESTestCase;
22+
23+
public class GeoTests extends ESTestCase {
24+
25+
public void testStub() {
26+
// the build expects unit tests to exist in a module, so here one is.
27+
}
28+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
setup:
2+
- do:
3+
indices.create:
4+
index: test
5+
body:
6+
settings:
7+
number_of_replicas: 0
8+
mappings:
9+
properties:
10+
location:
11+
type: geo_shape
12+
13+
- do:
14+
index:
15+
index: test
16+
id: 1
17+
body:
18+
location: "POINT (1.0 1.0)"
19+
20+
- do:
21+
indices.refresh: {}
22+
23+
---
24+
"Test Geo Shape Query":
25+
26+
- do:
27+
search:
28+
rest_total_hits_as_int: true
29+
body:
30+
query:
31+
bool:
32+
filter:
33+
geo_shape:
34+
location:
35+
shape:
36+
type: Envelope
37+
coordinates:
38+
- [-80.0, 34.0]
39+
- [43, -13.0]
40+
relation: within
41+
42+
- match:
43+
hits.total: 1
44+
45+
- match:
46+
hits.hits.0._id: "1"
47+
48+
---
49+
"Test Exists Query on geo_shape field":
50+
- do:
51+
search:
52+
rest_total_hits_as_int: true
53+
index: test
54+
body:
55+
query:
56+
exists:
57+
field: location
58+
59+
- match: {hits.total: 1}

modules/mapper-extras/src/test/java/org/elasticsearch/index/query/RankFeatureQueryBuilderTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@
3030
import org.elasticsearch.index.query.RankFeatureQueryBuilder.ScoreFunction;
3131
import org.elasticsearch.plugins.Plugin;
3232
import org.elasticsearch.test.AbstractQueryTestCase;
33+
import org.elasticsearch.test.TestGeoShapeFieldMapperPlugin;
3334

3435
import java.io.IOException;
3536
import java.util.ArrayList;
37+
import java.util.Arrays;
3638
import java.util.Collection;
37-
import java.util.Collections;
3839
import java.util.List;
3940

4041
import static org.hamcrest.CoreMatchers.instanceOf;
@@ -52,7 +53,7 @@ protected void initializeAdditionalMappings(MapperService mapperService) throws
5253

5354
@Override
5455
protected Collection<Class<? extends Plugin>> getPlugins() {
55-
return Collections.singleton(MapperExtrasPlugin.class);
56+
return Arrays.asList(MapperExtrasPlugin.class, TestGeoShapeFieldMapperPlugin.class);
5657
}
5758

5859
@Override

modules/parent-join/src/test/java/org/elasticsearch/join/aggregations/ChildrenTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@
2222
import org.elasticsearch.join.ParentJoinPlugin;
2323
import org.elasticsearch.plugins.Plugin;
2424
import org.elasticsearch.search.aggregations.BaseAggregationTestCase;
25+
import org.elasticsearch.test.TestGeoShapeFieldMapperPlugin;
2526

27+
import java.util.Arrays;
2628
import java.util.Collection;
27-
import java.util.Collections;
2829

2930
public class ChildrenTests extends BaseAggregationTestCase<ChildrenAggregationBuilder> {
3031

3132
@Override
3233
protected Collection<Class<? extends Plugin>> getPlugins() {
33-
return Collections.singleton(ParentJoinPlugin.class);
34+
return Arrays.asList(ParentJoinPlugin.class, TestGeoShapeFieldMapperPlugin.class);
3435
}
3536

3637
@Override

modules/parent-join/src/test/java/org/elasticsearch/join/aggregations/ParentTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,19 @@
1919

2020
package org.elasticsearch.join.aggregations;
2121

22+
import java.util.Arrays;
2223
import java.util.Collection;
23-
import java.util.Collections;
2424

2525
import org.elasticsearch.join.ParentJoinPlugin;
2626
import org.elasticsearch.plugins.Plugin;
2727
import org.elasticsearch.search.aggregations.BaseAggregationTestCase;
28+
import org.elasticsearch.test.TestGeoShapeFieldMapperPlugin;
2829

2930
public class ParentTests extends BaseAggregationTestCase<ParentAggregationBuilder> {
3031

3132
@Override
3233
protected Collection<Class<? extends Plugin>> getPlugins() {
33-
return Collections.singleton(ParentJoinPlugin.class);
34+
return Arrays.asList(ParentJoinPlugin.class, TestGeoShapeFieldMapperPlugin.class);
3435
}
3536

3637
@Override

modules/parent-join/src/test/java/org/elasticsearch/join/query/HasChildQueryBuilderTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@
5656
import org.elasticsearch.search.sort.FieldSortBuilder;
5757
import org.elasticsearch.search.sort.SortOrder;
5858
import org.elasticsearch.test.AbstractQueryTestCase;
59+
import org.elasticsearch.test.TestGeoShapeFieldMapperPlugin;
5960
import org.elasticsearch.test.VersionUtils;
6061

6162
import java.io.IOException;
63+
import java.util.Arrays;
6264
import java.util.Collection;
6365
import java.util.Collections;
6466
import java.util.HashMap;
@@ -85,7 +87,7 @@ public class HasChildQueryBuilderTests extends AbstractQueryTestCase<HasChildQue
8587

8688
@Override
8789
protected Collection<Class<? extends Plugin>> getPlugins() {
88-
return Collections.singletonList(ParentJoinPlugin.class);
90+
return Arrays.asList(ParentJoinPlugin.class, TestGeoShapeFieldMapperPlugin.class);
8991
}
9092

9193
@Override

modules/parent-join/src/test/java/org/elasticsearch/join/query/HasParentQueryBuilderTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@
4444
import org.elasticsearch.search.sort.FieldSortBuilder;
4545
import org.elasticsearch.search.sort.SortOrder;
4646
import org.elasticsearch.test.AbstractQueryTestCase;
47+
import org.elasticsearch.test.TestGeoShapeFieldMapperPlugin;
4748
import org.elasticsearch.test.VersionUtils;
4849

4950
import java.io.IOException;
51+
import java.util.Arrays;
5052
import java.util.Collection;
5153
import java.util.Collections;
5254
import java.util.HashMap;
@@ -70,7 +72,7 @@ public class HasParentQueryBuilderTests extends AbstractQueryTestCase<HasParentQ
7072

7173
@Override
7274
protected Collection<Class<? extends Plugin>> getPlugins() {
73-
return Collections.singletonList(ParentJoinPlugin.class);
75+
return Arrays.asList(ParentJoinPlugin.class, TestGeoShapeFieldMapperPlugin.class);
7476
}
7577

7678
@Override

0 commit comments

Comments
 (0)