|
@@ -15,6 +15,9 @@ import org.apache.lucene.search.IndexOrDocValuesQuery;
|
|
|
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;
|
|
@@ -23,9 +26,15 @@ import org.elasticsearch.geometry.utils.Geohash;
|
|
|
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;
|
|
@@ -35,10 +44,28 @@ import static org.hamcrest.CoreMatchers.notNullValue;
|
|
|
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(
|