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

Create new geo module and migrate geo_shape registration #53562

Merged
merged 27 commits into from
Apr 7, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
aab920f
Create new spatial-extras module and migrate geo_shape registration
talevy Mar 13, 2020
fe11a26
cover more test cases and take ownership of exists yaml tests
talevy Mar 13, 2020
fae51f5
more tests
talevy Mar 13, 2020
e7d8efd
more fixes
talevy Mar 13, 2020
ff1024d
fix enrich test
talevy Mar 13, 2020
99d4240
add empty unit tests
talevy Mar 13, 2020
3d9fb12
add license header
talevy Mar 13, 2020
136a2cf
moar
talevy Mar 13, 2020
d7f2279
singletonmap
talevy Mar 13, 2020
ad4a4bd
List.of -> Arrays.asList
talevy Mar 13, 2020
c954df7
refactor spatial-extras to geo
nknize Mar 18, 2020
f6d68f6
Merge branch 'master' into spatial-extras
nknize Mar 18, 2020
3daf046
spotless apply
nknize Mar 18, 2020
e45d92c
added TestGeoShapeFieldMapperPlugin to PinnedQueryBuilderTests
nknize Mar 23, 2020
e93f6a0
Merge remote-tracking branch 'elastic/master' into spatial-extras
talevy Mar 31, 2020
4329d0e
fix checkstyle
talevy Mar 31, 2020
40ce9d7
fix percolator query test
talevy Mar 31, 2020
508b175
Merge remote-tracking branch 'elastic/master' into spatial-extras
talevy Apr 1, 2020
64c0bea
try to make Percolator test happy
talevy Apr 1, 2020
558d32d
make gradle happy
talevy Apr 2, 2020
252d8e1
fix ShapeQueryBuilderTests
talevy Apr 2, 2020
4ccb497
no client-only nodes in percolator tests
talevy Apr 2, 2020
dbc9414
Merge remote-tracking branch 'elastic/master' into spatial-extras
talevy Apr 2, 2020
f1a4136
stop using smile in percolator test, no valid UTF8
talevy Apr 3, 2020
61f2b13
fix unsused imports
talevy Apr 3, 2020
917e538
Merge remote-tracking branch 'elastic/master' into spatial-extras
talevy Apr 3, 2020
be57a80
Merge remote-tracking branch 'elastic/master' into spatial-extras
talevy Apr 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
import org.elasticsearch.index.query.RankFeatureQueryBuilder.ScoreFunction;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.AbstractQueryTestCase;
import org.elasticsearch.test.TestGeoShapeFieldMapperPlugin;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

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

@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return Collections.singleton(MapperExtrasPlugin.class);
return List.of(MapperExtrasPlugin.class, TestGeoShapeFieldMapperPlugin.class);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is room to pull the TestGeoShapeFieldMapperPlugin to the parent test class and inherited by those that need it or need to extend to include more plugins. I could see it stay either way since it is fairly low impact and the dependency is expected to go away

talevy marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@
import org.elasticsearch.join.ParentJoinPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.search.aggregations.BaseAggregationTestCase;
import org.elasticsearch.test.TestGeoShapeFieldMapperPlugin;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class ChildrenTests extends BaseAggregationTestCase<ChildrenAggregationBuilder> {

@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return Collections.singleton(ParentJoinPlugin.class);
return List.of(ParentJoinPlugin.class, TestGeoShapeFieldMapperPlugin.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@
package org.elasticsearch.join.aggregations;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

import org.elasticsearch.join.ParentJoinPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.search.aggregations.BaseAggregationTestCase;
import org.elasticsearch.test.TestGeoShapeFieldMapperPlugin;

public class ParentTests extends BaseAggregationTestCase<ParentAggregationBuilder> {

@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return Collections.singleton(ParentJoinPlugin.class);
return List.of(ParentJoinPlugin.class, TestGeoShapeFieldMapperPlugin.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@
import org.elasticsearch.search.sort.FieldSortBuilder;
import org.elasticsearch.search.sort.SortOrder;
import org.elasticsearch.test.AbstractQueryTestCase;
import org.elasticsearch.test.TestGeoShapeFieldMapperPlugin;
import org.elasticsearch.test.VersionUtils;

import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
Expand All @@ -85,7 +87,7 @@ public class HasChildQueryBuilderTests extends AbstractQueryTestCase<HasChildQue

@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return Collections.singletonList(ParentJoinPlugin.class);
return List.of(ParentJoinPlugin.class, TestGeoShapeFieldMapperPlugin.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@
import org.elasticsearch.search.sort.FieldSortBuilder;
import org.elasticsearch.search.sort.SortOrder;
import org.elasticsearch.test.AbstractQueryTestCase;
import org.elasticsearch.test.TestGeoShapeFieldMapperPlugin;
import org.elasticsearch.test.VersionUtils;

import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
Expand All @@ -70,7 +72,7 @@ public class HasParentQueryBuilderTests extends AbstractQueryTestCase<HasParentQ

@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return Collections.singletonList(ParentJoinPlugin.class);
return List.of(ParentJoinPlugin.class, TestGeoShapeFieldMapperPlugin.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@
import org.elasticsearch.join.ParentJoinPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.AbstractQueryTestCase;
import org.elasticsearch.test.TestGeoShapeFieldMapperPlugin;
import org.hamcrest.Matchers;

import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.hamcrest.CoreMatchers.containsString;
Expand All @@ -61,7 +62,7 @@ public class ParentIdQueryBuilderTests extends AbstractQueryTestCase<ParentIdQue

@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return Collections.singletonList(ParentJoinPlugin.class);
return List.of(ParentJoinPlugin.class, TestGeoShapeFieldMapperPlugin.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.elasticsearch.ingest.RandomDocumentPicks;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.AbstractQueryTestCase;
import org.elasticsearch.test.TestGeoShapeFieldMapperPlugin;
import org.hamcrest.Matchers;

import java.io.IOException;
Expand Down Expand Up @@ -84,7 +85,7 @@ public class PercolateQueryBuilderTests extends AbstractQueryTestCase<PercolateQ

@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return Collections.singleton(PercolatorPlugin.class);
return List.of(PercolatorPlugin.class, TestGeoShapeFieldMapperPlugin.class);
}

@Override
Expand Down
23 changes: 23 additions & 0 deletions modules/spatial-extras/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

esplugin {
description 'Placeholder plugin for spatial features in ES. only registers geo-shape field mapper for now'
classname 'org.elasticsearch.spatial.SpatialExtrasPlugin'
talevy marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.elasticsearch.spatial;

import org.elasticsearch.index.mapper.AbstractGeometryFieldMapper;
import org.elasticsearch.index.mapper.GeoShapeFieldMapper;
import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.plugins.MapperPlugin;
import org.elasticsearch.plugins.Plugin;

import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;

public class SpatialExtrasPlugin extends Plugin implements MapperPlugin {

@Override
public Map<String, Mapper.TypeParser> getMappers() {
Map<String, Mapper.TypeParser> mappers = new LinkedHashMap<>();
mappers.put(GeoShapeFieldMapper.CONTENT_TYPE, new AbstractGeometryFieldMapper.TypeParser());
return Collections.unmodifiableMap(mappers);
talevy marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.elasticsearch.spatial;

import com.carrotsearch.randomizedtesting.annotations.Name;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate;
import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase;

/** Runs yaml rest tests */
public class SpatialExtrasClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase {

public SpatialExtrasClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) {
super(testCandidate);
}

@ParametersFactory
public static Iterable<Object[]> parameters() throws Exception {
return ESClientYamlSuiteTestCase.createParameters();
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
setup:
- do:
indices.create:
index: test
body:
settings:
number_of_replicas: 0
mappings:
properties:
location:
type: geo_shape

- do:
index:
index: test
id: 1
body:
location: "POINT (1.0 1.0)"

- do:
indices.refresh: {}

---
"Test Geo Shape Query":

- do:
search:
rest_total_hits_as_int: true
body:
query:
bool:
filter:
geo_shape:
location:
shape:
type: Envelope
coordinates:
- [-80.0, 34.0]
- [43, -13.0]
relation: within

- match:
hits.total: 1

- match:
hits.hits.0._id: "1"

---
"Test Exists Query on geo_shape field":
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:
exists:
field: location

- match: {hits.total: 1}
Loading