Skip to content

Issue 54628 #58151

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

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 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 @@ -37,10 +37,15 @@
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.geometry.Rectangle;
import org.elasticsearch.geometry.utils.Geohash;
import org.elasticsearch.index.mapper.GeoPointFieldMapper;
import org.elasticsearch.index.mapper.GeoPointFieldMapper.GeoPointFieldType;
import org.elasticsearch.index.mapper.GeoShapeFieldMapper;
import org.elasticsearch.index.mapper.MappedFieldType;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
Expand Down Expand Up @@ -76,6 +81,16 @@ public class GeoBoundingBoxQueryBuilder extends AbstractQueryBuilder<GeoBounding

private boolean ignoreUnmapped = DEFAULT_IGNORE_UNMAPPED;

protected static final List<String> validContentTypes =
Collections.unmodifiableList(
Arrays.asList(
GeoShapeFieldMapper.CONTENT_TYPE,
GeoPointFieldMapper.CONTENT_TYPE));

protected List<String> validContentTypes() {
return validContentTypes;
}

/**
* Create new bounding box query.
* @param fieldName name of index field containing geo coordinates to operate on.
Expand Down Expand Up @@ -312,10 +327,15 @@ public Query doToQuery(QueryShardContext context) {
throw new QueryShardException(context, "failed to find geo_point field [" + fieldName + "]");
}
}
if (!(fieldType instanceof GeoPointFieldType)) {
throw new QueryShardException(context, "field [" + fieldName + "] is not a geo_point field");
// if (!(fieldType instanceof GeoPointFieldType)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that above refers just to geo_point ("failed to find geo_point field ["). That might need to be updated.

// throw new QueryShardException(context, "field [" + fieldName + "] is not a geo_point field");
// }
if (!validContentTypes().contains(fieldType.typeName())) {
throw new QueryShardException(context,
"Field [" + fieldName + "] is of unsupported type [" + fieldType.typeName() + "]. ["
+ NAME + "] query supports the following types ["
+ String.join(",", validContentTypes()) + "]");
}

QueryValidationException exception = checkLatLon();
if (exception != null) {
throw new QueryShardException(context, "couldn't validate latitude/ longitude values", exception);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@
import org.elasticsearch.common.unit.DistanceUnit;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.mapper.GeoPointFieldMapper;
import org.elasticsearch.index.mapper.GeoPointFieldMapper.GeoPointFieldType;
import org.elasticsearch.index.mapper.GeoShapeFieldMapper;
import org.elasticsearch.index.mapper.MappedFieldType;

import java.io.IOException;
import java.util.Locale;
import java.util.Objects;
import java.util.*;

/**
* Filter results of a query to include only those within a specific distance to some
Expand Down Expand Up @@ -77,6 +78,15 @@ public class GeoDistanceQueryBuilder extends AbstractQueryBuilder<GeoDistanceQue

private boolean ignoreUnmapped = DEFAULT_IGNORE_UNMAPPED;

protected static final List<String> validContentTypes =
Collections.unmodifiableList(
Arrays.asList(
GeoShapeFieldMapper.CONTENT_TYPE,
GeoPointFieldMapper.CONTENT_TYPE));

protected List<String> validContentTypes() {
return validContentTypes;
}
/**
* Construct new GeoDistanceQueryBuilder.
* @param fieldName name of indexed geo field to operate distance computation on.
Expand Down Expand Up @@ -236,8 +246,15 @@ protected Query doToQuery(QueryShardContext shardContext) throws IOException {
}
}

if (!(fieldType instanceof GeoPointFieldType)) {
throw new QueryShardException(shardContext, "field [" + fieldName + "] is not a geo_point field");
// if (!(fieldType instanceof GeoPointFieldType)) {
// throw new QueryShardException(shardContext, "field [" + fieldName + "] is not a geo_point field");
// }

if (!validContentTypes().contains(fieldType.typeName())) {
throw new QueryShardException(shardContext,
"Field [" + fieldName + "] is of unsupported type [" + fieldType.typeName() + "]. ["
+ NAME + "] query supports the following types ["
+ String.join(",", validContentTypes()) + "]");
}

QueryValidationException exception = checkLatLon();
Expand Down