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

Don't index geo_shape field in AbstractBuilderTestCase #88437

Merged
merged 4 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -19,7 +19,6 @@
import org.elasticsearch.index.query.SearchExecutionContext;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.AbstractQueryTestCase;
import org.elasticsearch.test.TestGeoShapeFieldMapperPlugin;

import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -54,7 +53,7 @@ protected void initializeAdditionalMappings(MapperService mapperService) throws

@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return Arrays.asList(MapperExtrasPlugin.class, TestGeoShapeFieldMapperPlugin.class);
return Arrays.asList(MapperExtrasPlugin.class);
}

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

import java.util.Arrays;
import java.util.Collection;
Expand All @@ -20,7 +19,7 @@ public class ChildrenTests extends BaseAggregationTestCase<ChildrenAggregationBu

@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return Arrays.asList(ParentJoinPlugin.class, TestGeoShapeFieldMapperPlugin.class);
return Arrays.asList(ParentJoinPlugin.class);
}

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

import java.util.Arrays;
import java.util.Collection;
Expand All @@ -20,7 +19,7 @@ public class ParentTests extends BaseAggregationTestCase<ParentAggregationBuilde

@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return Arrays.asList(ParentJoinPlugin.class, TestGeoShapeFieldMapperPlugin.class);
return Arrays.asList(ParentJoinPlugin.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
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 org.elasticsearch.xcontent.XContentBuilder;

Expand Down Expand Up @@ -77,7 +76,7 @@ public class HasChildQueryBuilderTests extends AbstractQueryTestCase<HasChildQue

@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return Arrays.asList(ParentJoinPlugin.class, TestGeoShapeFieldMapperPlugin.class);
return Arrays.asList(ParentJoinPlugin.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
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 org.elasticsearch.xcontent.XContentBuilder;

Expand Down Expand Up @@ -60,7 +59,7 @@ public class HasParentQueryBuilderTests extends AbstractQueryTestCase<HasParentQ

@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return Arrays.asList(ParentJoinPlugin.class, TestGeoShapeFieldMapperPlugin.class);
return Arrays.asList(ParentJoinPlugin.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.elasticsearch.join.ParentJoinPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.AbstractQueryTestCase;
import org.elasticsearch.test.TestGeoShapeFieldMapperPlugin;
import org.elasticsearch.xcontent.XContentBuilder;
import org.hamcrest.Matchers;

Expand All @@ -48,7 +47,7 @@ public class ParentIdQueryBuilderTests extends AbstractQueryTestCase<ParentIdQue

@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return Arrays.asList(ParentJoinPlugin.class, TestGeoShapeFieldMapperPlugin.class);
return Arrays.asList(ParentJoinPlugin.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.elasticsearch.ingest.RandomDocumentPicks;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.AbstractQueryTestCase;
import org.elasticsearch.test.TestGeoShapeFieldMapperPlugin;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentFactory;
import org.elasticsearch.xcontent.XContentParser;
Expand Down Expand Up @@ -77,7 +76,7 @@ public class PercolateQueryBuilderTests extends AbstractQueryTestCase<PercolateQ

@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return Arrays.asList(PercolatorPlugin.class, TestGeoShapeFieldMapperPlugin.class);
return Arrays.asList(PercolatorPlugin.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import org.apache.lucene.search.MatchNoDocsQuery;
import org.apache.lucene.search.Query;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.common.geo.GeoUtils;
import org.elasticsearch.geo.GeometryTestUtils;
Expand All @@ -23,9 +26,15 @@
import org.elasticsearch.index.mapper.GeoPointFieldMapper;
import org.elasticsearch.index.mapper.GeoShapeFieldMapper;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.AbstractQueryTestCase;
import org.elasticsearch.test.TestGeoShapeFieldMapperPlugin;
import org.elasticsearch.xcontent.XContentBuilder;

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

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.instanceOf;
Expand All @@ -35,10 +44,28 @@
public class GeoBoundingBoxQueryBuilderTests extends AbstractQueryTestCase<GeoBoundingBoxQueryBuilder> {
/** Randomly generate either NaN or one of the two infinity values. */
private static final Double[] brokenDoubles = { Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY };
private static final String GEO_SHAPE_FIELD_NAME = "mapped_geo_shape";
protected static final String GEO_SHAPE_ALIAS_FIELD_NAME = "mapped_geo_shape_alias";

@Override
protected void initializeAdditionalMappings(MapperService mapperService) throws IOException {
final XContentBuilder builder = PutMappingRequest.simpleMapping(
GEO_SHAPE_FIELD_NAME,
"type=geo_shape",
GEO_SHAPE_ALIAS_FIELD_NAME,
"type=alias,path=" + GEO_SHAPE_FIELD_NAME
);
mapperService.merge("_doc", new CompressedXContent(Strings.toString(builder)), MapperService.MergeReason.MAPPING_UPDATE);
}

@SuppressWarnings("deprecation") // dependencies in server for geo_shape field should be decoupled
protected Collection<Class<? extends Plugin>> getPlugins() {
return Collections.singletonList(TestGeoShapeFieldMapperPlugin.class);
}

@Override
protected GeoBoundingBoxQueryBuilder doCreateTestQueryBuilder() {
String fieldName = randomFrom(GEO_POINT_FIELD_NAME, GEO_POINT_ALIAS_FIELD_NAME, GEO_SHAPE_FIELD_NAME);
String fieldName = randomFrom(GEO_POINT_FIELD_NAME, GEO_POINT_ALIAS_FIELD_NAME, GEO_SHAPE_FIELD_NAME, GEO_SHAPE_ALIAS_FIELD_NAME);
GeoBoundingBoxQueryBuilder builder = new GeoBoundingBoxQueryBuilder(fieldName);
// make sure that minX != maxX and minY != maxY after geohash encoding
Rectangle box = randomValueOtherThanMany(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,26 @@
import org.apache.lucene.search.IndexOrDocValuesQuery;
import org.apache.lucene.search.MatchNoDocsQuery;
import org.apache.lucene.search.Query;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.geo.GeoDistance;
import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.common.unit.DistanceUnit;
import org.elasticsearch.geo.GeometryTestUtils;
import org.elasticsearch.index.mapper.GeoPointFieldMapper;
import org.elasticsearch.index.mapper.GeoShapeFieldMapper;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.AbstractQueryTestCase;
import org.elasticsearch.test.TestGeoShapeFieldMapperPlugin;
import org.elasticsearch.xcontent.XContentBuilder;

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

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.instanceOf;
Expand All @@ -33,9 +42,28 @@
@SuppressWarnings("checkstyle:MissingJavadocMethod")
public class GeoDistanceQueryBuilderTests extends AbstractQueryTestCase<GeoDistanceQueryBuilder> {

private static final String GEO_SHAPE_FIELD_NAME = "mapped_geo_shape";
protected static final String GEO_SHAPE_ALIAS_FIELD_NAME = "mapped_geo_shape_alias";

@Override
protected void initializeAdditionalMappings(MapperService mapperService) throws IOException {
final XContentBuilder builder = PutMappingRequest.simpleMapping(
GEO_SHAPE_FIELD_NAME,
"type=geo_shape",
GEO_SHAPE_ALIAS_FIELD_NAME,
"type=alias,path=" + GEO_SHAPE_FIELD_NAME
);
mapperService.merge("_doc", new CompressedXContent(Strings.toString(builder)), MapperService.MergeReason.MAPPING_UPDATE);
}

@SuppressWarnings("deprecation") // dependencies in server for geo_shape field should be decoupled
protected Collection<Class<? extends Plugin>> getPlugins() {
return Collections.singletonList(TestGeoShapeFieldMapperPlugin.class);
}

@Override
protected GeoDistanceQueryBuilder doCreateTestQueryBuilder() {
String fieldName = randomFrom(GEO_POINT_FIELD_NAME, GEO_POINT_ALIAS_FIELD_NAME, GEO_SHAPE_FIELD_NAME);
String fieldName = randomFrom(GEO_POINT_FIELD_NAME, GEO_POINT_ALIAS_FIELD_NAME, GEO_SHAPE_FIELD_NAME, GEO_SHAPE_ALIAS_FIELD_NAME);
GeoDistanceQueryBuilder qb = new GeoDistanceQueryBuilder(fieldName);
String distance = "" + randomDouble();
if (randomBoolean()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,37 @@
package org.elasticsearch.index.query;

import org.elasticsearch.Version;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.geo.ShapeRelation;
import org.elasticsearch.geo.GeometryTestUtils;
import org.elasticsearch.geometry.Geometry;
import org.elasticsearch.geometry.ShapeType;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.TestGeoShapeFieldMapperPlugin;
import org.elasticsearch.xcontent.XContentBuilder;

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

public class GeoShapeQueryBuilderGeoShapeTests extends GeoShapeQueryBuilderTests {

private static final String GEO_SHAPE_FIELD_NAME = "mapped_geo_shape";

@Override
protected void initializeAdditionalMappings(MapperService mapperService) throws IOException {
XContentBuilder builder = PutMappingRequest.simpleMapping(GEO_SHAPE_FIELD_NAME, "type=geo_shape");
mapperService.merge("_doc", new CompressedXContent(Strings.toString(builder)), MapperService.MergeReason.MAPPING_UPDATE);
}

@SuppressWarnings("deprecation") // dependencies in server for geo_shape field should be decoupled
protected Collection<Class<? extends Plugin>> getPlugins() {
return Collections.singletonList(TestGeoShapeFieldMapperPlugin.class);
}

protected String fieldName() {
return GEO_SHAPE_FIELD_NAME;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ protected TermsQueryBuilder doCreateTestQueryBuilder() {
String fieldName = randomValueOtherThanMany(
choice -> choice.equals(GEO_POINT_FIELD_NAME)
|| choice.equals(GEO_POINT_ALIAS_FIELD_NAME)
|| choice.equals(GEO_SHAPE_FIELD_NAME)
|| choice.equals(INT_RANGE_FIELD_NAME)
|| choice.equals(DATE_RANGE_FIELD_NAME)
|| choice.equals(DATE_NANOS_FIELD_NAME), // TODO: needs testing for date_nanos type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptType;
import org.elasticsearch.test.AbstractQueryTestCase;
import org.elasticsearch.test.TestGeoShapeFieldMapperPlugin;
import org.elasticsearch.test.rest.ObjectPath;

import java.io.IOException;
Expand All @@ -61,7 +60,7 @@ public class TermsSetQueryBuilderTests extends AbstractQueryTestCase<TermsSetQue

@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return Arrays.asList(CustomScriptPlugin.class, TestGeoShapeFieldMapperPlugin.class);
return Arrays.asList(CustomScriptPlugin.class);
}

@Override
Expand All @@ -76,10 +75,7 @@ protected void initializeAdditionalMappings(MapperService mapperService) throws

@Override
protected TermsSetQueryBuilder doCreateTestQueryBuilder() {
String fieldName = randomValueOtherThanMany(
value -> value.equals(GEO_POINT_FIELD_NAME) || value.equals(GEO_SHAPE_FIELD_NAME),
() -> randomFrom(MAPPED_FIELD_NAMES)
);
String fieldName = randomValueOtherThanMany(value -> value.equals(GEO_POINT_FIELD_NAME), () -> randomFrom(MAPPED_FIELD_NAMES));
List<?> randomTerms = randomValues(fieldName);
TermsSetQueryBuilder queryBuilder = new TermsSetQueryBuilder(TEXT_FIELD_NAME, randomTerms);
if (randomBoolean()) {
Expand Down Expand Up @@ -151,9 +147,7 @@ public TermsSetQueryBuilder mutateInstance(final TermsSetQueryBuilder instance)

switch (randomIntBetween(0, 3)) {
case 0 -> {
Predicate<String> predicate = s -> s.equals(instance.getFieldName()) == false
&& s.equals(GEO_POINT_FIELD_NAME) == false
&& s.equals(GEO_SHAPE_FIELD_NAME) == false;
Predicate<String> predicate = s -> s.equals(instance.getFieldName()) == false && s.equals(GEO_POINT_FIELD_NAME) == false;
fieldName = randomValueOtherThanMany(predicate, () -> randomFrom(MAPPED_FIELD_NAMES));
values = randomValues(fieldName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import org.elasticsearch.script.ScriptType;
import org.elasticsearch.search.MultiValueMode;
import org.elasticsearch.test.AbstractQueryTestCase;
import org.elasticsearch.test.TestGeoShapeFieldMapperPlugin;
import org.elasticsearch.xcontent.XContentParseException;
import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentType;
Expand Down Expand Up @@ -90,7 +89,7 @@ public class FunctionScoreQueryBuilderTests extends AbstractQueryTestCase<Functi

@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return Arrays.asList(TestPlugin.class, TestGeoShapeFieldMapperPlugin.class);
return Arrays.asList(TestPlugin.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,14 @@
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.SearchExecutionContext;
import org.elasticsearch.index.query.TermQueryBuilder;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.AbstractBuilderTestCase;
import org.elasticsearch.test.AbstractQueryTestCase;
import org.elasticsearch.test.TestGeoShapeFieldMapperPlugin;
import org.elasticsearch.test.VersionUtils;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentFactory;

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

import static org.hamcrest.Matchers.containsString;
Expand All @@ -46,11 +42,6 @@ public class KnnVectorQueryBuilderTests extends AbstractQueryTestCase<KnnVectorQ
private static final String VECTOR_ALIAS_FIELD = "vector_alias";
private static final int VECTOR_DIMENSION = 3;

@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return Arrays.asList(TestGeoShapeFieldMapperPlugin.class);
}

@Override
protected void initializeAdditionalMappings(MapperService mapperService) throws IOException {
XContentBuilder builder = XContentFactory.jsonBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.search.aggregations.BaseAggregationTestCase;
import org.elasticsearch.test.TestGeoShapeFieldMapperPlugin;

import java.util.Arrays;
import java.util.Collection;

public class DelayedShardAggregationBuilderTests extends BaseAggregationTestCase<DelayedShardAggregationBuilder> {
@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return Arrays.asList(DelayedShardAggregationPlugin.class, TestGeoShapeFieldMapperPlugin.class);
return Arrays.asList(DelayedShardAggregationPlugin.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.elasticsearch.index.query.SearchExecutionContext;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.AbstractQueryTestCase;
import org.elasticsearch.test.TestGeoShapeFieldMapperPlugin;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -24,7 +23,7 @@
public class ErrorQueryBuilderTests extends AbstractQueryTestCase<ErrorQueryBuilder> {
@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return Arrays.asList(ErrorQueryPlugin.class, TestGeoShapeFieldMapperPlugin.class);
return Arrays.asList(ErrorQueryPlugin.class);
}

@Override
Expand Down
Loading