Remove deprecated geo query parameters, and GeoPointDistanceRangeQuery

This commit removes the following queries and parameters (which were deprecated in 5.0):

* GeoPointDistanceRangeQuery
* coerce, and ignore_malformed for GeoBoundingBoxQuery, GeoDistanceQuery, GeoPolygonQuery, and GeoDistanceSort
This commit is contained in:
Nicholas Knize 2017-01-30 17:20:43 -06:00
parent f1e1975882
commit b1a6b227e1
11 changed files with 20 additions and 474 deletions

View File

@ -1,124 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.apache.lucene.spatial.geopoint.search;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.spatial.geopoint.document.GeoPointField.TermEncoding;
/** Implements a point distance range query on a GeoPoint field. This is based on
* {@code org.apache.lucene.spatial.geopoint.search.GeoPointDistanceQuery} and is implemented using a
* {@code org.apache.lucene.search.BooleanClause.MUST_NOT} clause to exclude any points that fall within
* minRadiusMeters from the provided point.
* <p>
* NOTE: this query does not correctly support multi-value docs (see: https://issues.apache.org/jira/browse/LUCENE-7126)
* <br>
* TODO: remove this per ISSUE #17658
**/
public final class XGeoPointDistanceRangeQuery extends GeoPointDistanceQuery {
/** minimum distance range (in meters) from lat, lon center location, maximum is inherited */
protected final double minRadiusMeters;
/**
* Constructs a query for all {@link org.apache.lucene.spatial.geopoint.document.GeoPointField} types within a minimum / maximum
* distance (in meters) range from a given point
*/
public XGeoPointDistanceRangeQuery(final String field, final double centerLat, final double centerLon,
final double minRadiusMeters, final double maxRadiusMeters) {
this(field, TermEncoding.PREFIX, centerLat, centerLon, minRadiusMeters, maxRadiusMeters);
}
/**
* Constructs a query for all {@link org.apache.lucene.spatial.geopoint.document.GeoPointField} types within a minimum / maximum
* distance (in meters) range from a given point. Accepts an optional
* {@link org.apache.lucene.spatial.geopoint.document.GeoPointField.TermEncoding}
*/
public XGeoPointDistanceRangeQuery(final String field, final TermEncoding termEncoding, final double centerLat, final double centerLon,
final double minRadiusMeters, final double maxRadius) {
super(field, termEncoding, centerLat, centerLon, maxRadius);
this.minRadiusMeters = minRadiusMeters;
}
@Override
public Query rewrite(IndexReader reader) {
Query q = super.rewrite(reader);
if (minRadiusMeters == 0.0) {
return q;
}
// add an exclusion query
BooleanQuery.Builder bqb = new BooleanQuery.Builder();
// create a new exclusion query
GeoPointDistanceQuery exclude = new GeoPointDistanceQuery(field, termEncoding, centerLat, centerLon, minRadiusMeters);
// full map search
// if (radiusMeters >= GeoProjectionUtils.SEMIMINOR_AXIS) {
// bqb.add(new BooleanClause(new GeoPointInBBoxQuery(this.field, -180.0, -90.0, 180.0, 90.0), BooleanClause.Occur.MUST));
// } else {
bqb.add(new BooleanClause(q, BooleanClause.Occur.MUST));
// }
bqb.add(new BooleanClause(exclude, BooleanClause.Occur.MUST_NOT));
return bqb.build();
}
@Override
public String toString(String field) {
final StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(':');
if (!this.field.equals(field)) {
sb.append(" field=");
sb.append(this.field);
sb.append(':');
}
return sb.append( " Center: [")
.append(centerLat)
.append(',')
.append(centerLon)
.append(']')
.append(" From Distance: ")
.append(minRadiusMeters)
.append(" m")
.append(" To Distance: ")
.append(radiusMeters)
.append(" m")
.append(" Lower Left: [")
.append(minLat)
.append(',')
.append(minLon)
.append(']')
.append(" Upper Right: [")
.append(maxLat)
.append(',')
.append(maxLon)
.append("]")
.toString();
}
/** getter method for minimum distance */
public double getMinRadiusMeters() {
return this.minRadiusMeters;
}
/** getter method for maximum distance */
public double getMaxRadiusMeters() {
return this.radiusMeters;
}
}

View File

@ -61,10 +61,6 @@ public class GeoBoundingBoxQueryBuilder extends AbstractQueryBuilder<GeoBounding
private static final ParseField TYPE_FIELD = new ParseField("type");
private static final ParseField VALIDATION_METHOD_FIELD = new ParseField("validation_method");
private static final ParseField COERCE_FIELD =new ParseField("coerce", "normalize")
.withAllDeprecated("validation_method");
private static final ParseField IGNORE_MALFORMED_FIELD = new ParseField("ignore_malformed")
.withAllDeprecated("validation_method");
private static final ParseField FIELD_FIELD = new ParseField("field");
private static final ParseField TOP_FIELD = new ParseField("top");
private static final ParseField BOTTOM_FIELD = new ParseField("bottom");
@ -387,8 +383,6 @@ public class GeoBoundingBoxQueryBuilder extends AbstractQueryBuilder<GeoBounding
String queryName = null;
String currentFieldName = null;
XContentParser.Token token;
boolean coerce = GeoValidationMethod.DEFAULT_LENIENT_PARSING;
boolean ignoreMalformed = GeoValidationMethod.DEFAULT_LENIENT_PARSING;
GeoValidationMethod validationMethod = null;
boolean ignoreUnmapped = DEFAULT_IGNORE_UNMAPPED;
@ -450,19 +444,12 @@ public class GeoBoundingBoxQueryBuilder extends AbstractQueryBuilder<GeoBounding
queryName = parser.text();
} else if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName)) {
boost = parser.floatValue();
} else if (COERCE_FIELD.match(currentFieldName)) {
coerce = parser.booleanValue();
if (coerce) {
ignoreMalformed = true;
}
} else if (VALIDATION_METHOD_FIELD.match(currentFieldName)) {
validationMethod = GeoValidationMethod.fromString(parser.text());
} else if (IGNORE_UNMAPPED_FIELD.match(currentFieldName)) {
ignoreUnmapped = parser.booleanValue();
} else if (TYPE_FIELD.match(currentFieldName)) {
type = parser.text();
} else if (IGNORE_MALFORMED_FIELD.match(currentFieldName)) {
ignoreMalformed = parser.booleanValue();
} else {
throw new ParsingException(parser.getTokenLocation(), "failed to parse [{}] query. unexpected field [{}]",
NAME, currentFieldName);
@ -481,8 +468,6 @@ public class GeoBoundingBoxQueryBuilder extends AbstractQueryBuilder<GeoBounding
if (validationMethod != null) {
// ignore deprecated coerce/ignoreMalformed settings if validationMethod is set
builder.setValidationMethod(validationMethod);
} else {
builder.setValidationMethod(GeoValidationMethod.infer(coerce, ignoreMalformed));
}
return builder;
}

View File

@ -48,17 +48,10 @@ import java.util.Objects;
public class GeoDistanceQueryBuilder extends AbstractQueryBuilder<GeoDistanceQueryBuilder> {
public static final String NAME = "geo_distance";
/** Default for latitude normalization (as of this writing true).*/
public static final boolean DEFAULT_NORMALIZE_LAT = true;
/** Default for longitude normalization (as of this writing true). */
public static final boolean DEFAULT_NORMALIZE_LON = true;
/** Default for distance unit computation. */
public static final DistanceUnit DEFAULT_DISTANCE_UNIT = DistanceUnit.DEFAULT;
/** Default for geo distance computation. */
public static final GeoDistance DEFAULT_GEO_DISTANCE = GeoDistance.ARC;
/** Default for optimising query through pre computed bounding box query. */
@Deprecated
public static final String DEFAULT_OPTIMIZE_BBOX = "memory";
/**
* The default value for ignore_unmapped.
@ -66,11 +59,6 @@ public class GeoDistanceQueryBuilder extends AbstractQueryBuilder<GeoDistanceQue
public static final boolean DEFAULT_IGNORE_UNMAPPED = false;
private static final ParseField VALIDATION_METHOD_FIELD = new ParseField("validation_method");
private static final ParseField IGNORE_MALFORMED_FIELD = new ParseField("ignore_malformed").withAllDeprecated("validation_method");
private static final ParseField COERCE_FIELD = new ParseField("coerce", "normalize").withAllDeprecated("validation_method");
@Deprecated
private static final ParseField OPTIMIZE_BBOX_FIELD = new ParseField("optimize_bbox")
.withAllDeprecated("no replacement: `optimize_bbox` is no longer supported due to recent improvements");
private static final ParseField DISTANCE_TYPE_FIELD = new ParseField("distance_type");
private static final ParseField UNIT_FIELD = new ParseField("unit");
private static final ParseField DISTANCE_FIELD = new ParseField("distance");
@ -83,8 +71,6 @@ public class GeoDistanceQueryBuilder extends AbstractQueryBuilder<GeoDistanceQue
private GeoPoint center = new GeoPoint(Double.NaN, Double.NaN);
/** Algorithm to use for distance computation. */
private GeoDistance geoDistance = GeoDistance.ARC;
/** Whether or not to use a bbox for pre-filtering. TODO change to enum? */
private String optimizeBbox = null;
/** How strict should geo coordinate validation be? */
private GeoValidationMethod validationMethod = GeoValidationMethod.DEFAULT;
@ -110,7 +96,6 @@ public class GeoDistanceQueryBuilder extends AbstractQueryBuilder<GeoDistanceQue
distance = in.readDouble();
validationMethod = GeoValidationMethod.readFromStream(in);
center = in.readGeoPoint();
optimizeBbox = in.readOptionalString();
geoDistance = GeoDistance.readFromStream(in);
ignoreUnmapped = in.readBoolean();
}
@ -121,7 +106,6 @@ public class GeoDistanceQueryBuilder extends AbstractQueryBuilder<GeoDistanceQue
out.writeDouble(distance);
validationMethod.writeTo(out);
out.writeGeoPoint(center);
out.writeOptionalString(optimizeBbox);
geoDistance.writeTo(out);
out.writeBoolean(ignoreUnmapped);
}
@ -211,28 +195,6 @@ public class GeoDistanceQueryBuilder extends AbstractQueryBuilder<GeoDistanceQue
return this.geoDistance;
}
/**
* Set this to memory or indexed if before running the distance
* calculation you want to limit the candidates to hits in the
* enclosing bounding box.
* @deprecated
**/
@Deprecated
public GeoDistanceQueryBuilder optimizeBbox(String optimizeBbox) {
this.optimizeBbox = optimizeBbox;
return this;
}
/**
* Returns whether or not to run a BoundingBox query prior to
* distance query for optimization purposes.
* @deprecated
**/
@Deprecated
public String optimizeBbox() {
return this.optimizeBbox;
}
/** Set validation method for geo coordinates. */
public void setValidationMethod(GeoValidationMethod method) {
this.validationMethod = method;
@ -296,9 +258,6 @@ public class GeoDistanceQueryBuilder extends AbstractQueryBuilder<GeoDistanceQue
builder.startArray(fieldName).value(center.lon()).value(center.lat()).endArray();
builder.field(DISTANCE_FIELD.getPreferredName(), distance);
builder.field(DISTANCE_TYPE_FIELD.getPreferredName(), geoDistance.name().toLowerCase(Locale.ROOT));
if (Strings.isEmpty(optimizeBbox) == false) {
builder.field(OPTIMIZE_BBOX_FIELD.getPreferredName(), optimizeBbox);
}
builder.field(VALIDATION_METHOD_FIELD.getPreferredName(), validationMethod);
builder.field(IGNORE_UNMAPPED_FIELD.getPreferredName(), ignoreUnmapped);
printBoostAndQueryName(builder);
@ -318,9 +277,6 @@ public class GeoDistanceQueryBuilder extends AbstractQueryBuilder<GeoDistanceQue
Object vDistance = null;
DistanceUnit unit = GeoDistanceQueryBuilder.DEFAULT_DISTANCE_UNIT;
GeoDistance geoDistance = GeoDistanceQueryBuilder.DEFAULT_GEO_DISTANCE;
String optimizeBbox = null;
boolean coerce = GeoValidationMethod.DEFAULT_LENIENT_PARSING;
boolean ignoreMalformed = GeoValidationMethod.DEFAULT_LENIENT_PARSING;
GeoValidationMethod validationMethod = null;
boolean ignoreUnmapped = DEFAULT_IGNORE_UNMAPPED;
@ -374,15 +330,6 @@ public class GeoDistanceQueryBuilder extends AbstractQueryBuilder<GeoDistanceQue
queryName = parser.text();
} else if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName)) {
boost = parser.floatValue();
} else if (OPTIMIZE_BBOX_FIELD.match(currentFieldName)) {
optimizeBbox = parser.textOrNull();
} else if (COERCE_FIELD.match(currentFieldName)) {
coerce = parser.booleanValue();
if (coerce) {
ignoreMalformed = true;
}
} else if (IGNORE_MALFORMED_FIELD.match(currentFieldName)) {
ignoreMalformed = parser.booleanValue();
} else if (IGNORE_UNMAPPED_FIELD.match(currentFieldName)) {
ignoreUnmapped = parser.booleanValue();
} else if (VALIDATION_METHOD_FIELD.match(currentFieldName)) {
@ -392,8 +339,8 @@ public class GeoDistanceQueryBuilder extends AbstractQueryBuilder<GeoDistanceQue
point.resetFromString(parser.text());
fieldName = currentFieldName;
} else {
throw new ParsingException(parser.getTokenLocation(), "[" + GeoDistanceQueryBuilder.NAME +
"] field name already set to [" + fieldName + "] but found [" + currentFieldName + "]");
throw new ParsingException(parser.getTokenLocation(), "failed to parse [{}] query. unexpected field [{}]",
NAME, currentFieldName);
}
}
}
@ -412,10 +359,7 @@ public class GeoDistanceQueryBuilder extends AbstractQueryBuilder<GeoDistanceQue
qb.point(point);
if (validationMethod != null) {
qb.setValidationMethod(validationMethod);
} else {
qb.setValidationMethod(GeoValidationMethod.infer(coerce, ignoreMalformed));
}
qb.optimizeBbox(optimizeBbox);
qb.geoDistance(geoDistance);
qb.boost(boost);
qb.queryName(queryName);
@ -425,7 +369,7 @@ public class GeoDistanceQueryBuilder extends AbstractQueryBuilder<GeoDistanceQue
@Override
protected int doHashCode() {
return Objects.hash(center, geoDistance, optimizeBbox, distance, validationMethod, ignoreUnmapped);
return Objects.hash(center, geoDistance, distance, validationMethod, ignoreUnmapped);
}
@Override
@ -434,7 +378,6 @@ public class GeoDistanceQueryBuilder extends AbstractQueryBuilder<GeoDistanceQue
(distance == other.distance) &&
Objects.equals(validationMethod, other.validationMethod) &&
Objects.equals(center, other.center) &&
Objects.equals(optimizeBbox, other.optimizeBbox) &&
Objects.equals(geoDistance, other.geoDistance) &&
Objects.equals(ignoreUnmapped, other.ignoreUnmapped);
}

View File

@ -48,9 +48,6 @@ public class GeoPolygonQueryBuilder extends AbstractQueryBuilder<GeoPolygonQuery
* The default value for ignore_unmapped.
*/
public static final boolean DEFAULT_IGNORE_UNMAPPED = false;
private static final ParseField COERCE_FIELD = new ParseField("coerce", "normalize").withAllDeprecated("validation_method");
private static final ParseField IGNORE_MALFORMED_FIELD = new ParseField("ignore_malformed").withAllDeprecated("validation_method");
private static final ParseField VALIDATION_METHOD = new ParseField("validation_method");
private static final ParseField POINTS_FIELD = new ParseField("points");
private static final ParseField IGNORE_UNMAPPED_FIELD = new ParseField("ignore_unmapped");
@ -232,8 +229,6 @@ public class GeoPolygonQueryBuilder extends AbstractQueryBuilder<GeoPolygonQuery
List<GeoPoint> shell = null;
Float boost = null;
boolean coerce = GeoValidationMethod.DEFAULT_LENIENT_PARSING;
boolean ignoreMalformed = GeoValidationMethod.DEFAULT_LENIENT_PARSING;
GeoValidationMethod validationMethod = null;
String queryName = null;
String currentFieldName = null;
@ -271,15 +266,8 @@ public class GeoPolygonQueryBuilder extends AbstractQueryBuilder<GeoPolygonQuery
queryName = parser.text();
} else if ("boost".equals(currentFieldName)) {
boost = parser.floatValue();
} else if (COERCE_FIELD.match(currentFieldName)) {
coerce = parser.booleanValue();
if (coerce) {
ignoreMalformed = true;
}
} else if (IGNORE_UNMAPPED_FIELD.match(currentFieldName)) {
ignoreUnmapped = parser.booleanValue();
} else if (IGNORE_MALFORMED_FIELD.match(currentFieldName)) {
ignoreMalformed = parser.booleanValue();
} else if (VALIDATION_METHOD.match(currentFieldName)) {
validationMethod = GeoValidationMethod.fromString(parser.text());
} else {
@ -294,8 +282,6 @@ public class GeoPolygonQueryBuilder extends AbstractQueryBuilder<GeoPolygonQuery
if (validationMethod != null) {
// if GeoValidationMethod was explicitly set ignore deprecated coerce and ignoreMalformed settings
builder.setValidationMethod(validationMethod);
} else {
builder.setValidationMethod(GeoValidationMethod.infer(coerce, ignoreMalformed));
}
if (queryName != null) {

View File

@ -72,8 +72,6 @@ public class GeoDistanceSortBuilder extends SortBuilder<GeoDistanceSortBuilder>
private static final ParseField UNIT_FIELD = new ParseField("unit");
private static final ParseField DISTANCE_TYPE_FIELD = new ParseField("distance_type");
private static final ParseField VALIDATION_METHOD_FIELD = new ParseField("validation_method");
private static final ParseField IGNORE_MALFORMED_FIELD = new ParseField("ignore_malformed").withAllDeprecated("validation_method");
private static final ParseField COERCE_FIELD = new ParseField("coerce", "normalize").withAllDeprecated("validation_method");
private static final ParseField SORTMODE_FIELD = new ParseField("mode", "sort_mode");
private final String fieldName;
@ -405,9 +403,6 @@ public class GeoDistanceSortBuilder extends SortBuilder<GeoDistanceSortBuilder>
SortMode sortMode = null;
QueryBuilder nestedFilter = null;
String nestedPath = null;
boolean coerce = GeoValidationMethod.DEFAULT_LENIENT_PARSING;
boolean ignoreMalformed = GeoValidationMethod.DEFAULT_LENIENT_PARSING;
GeoValidationMethod validation = null;
XContentParser.Token token;
@ -443,16 +438,6 @@ public class GeoDistanceSortBuilder extends SortBuilder<GeoDistanceSortBuilder>
unit = DistanceUnit.fromString(parser.text());
} else if (DISTANCE_TYPE_FIELD.match(currentName)) {
geoDistance = GeoDistance.fromString(parser.text());
} else if (COERCE_FIELD.match(currentName)) {
coerce = parser.booleanValue();
if (coerce) {
ignoreMalformed = true;
}
} else if (IGNORE_MALFORMED_FIELD.match(currentName)) {
boolean ignore_malformed_value = parser.booleanValue();
if (coerce == false) {
ignoreMalformed = ignore_malformed_value;
}
} else if (VALIDATION_METHOD_FIELD.match(currentName)) {
validation = GeoValidationMethod.fromString(parser.text());
} else if (SORTMODE_FIELD.match(currentName)) {
@ -472,11 +457,17 @@ public class GeoDistanceSortBuilder extends SortBuilder<GeoDistanceSortBuilder>
point.resetFromString(parser.text());
geoPoints.add(point);
fieldName = currentName;
} else {
} else if (fieldName.equals(currentName)){
throw new ParsingException(
parser.getTokenLocation(),
"Only geohashes of type string supported for field [{}]",
currentName);
} else {
throw new ParsingException(
parser.getTokenLocation(),
"[{}] does not support [{}]",
NAME, currentName
);
}
}
}
@ -492,11 +483,7 @@ public class GeoDistanceSortBuilder extends SortBuilder<GeoDistanceSortBuilder>
result.setNestedFilter(nestedFilter);
}
result.setNestedPath(nestedPath);
if (validation == null) {
// looks like either validation was left unset or we are parsing old validation json
result.validation(GeoValidationMethod.infer(coerce, ignoreMalformed));
} else {
// ignore deprecated coerce/ignore_malformed
if (validation != null) {
result.validation(validation);
}
return result;

View File

@ -406,43 +406,6 @@ public class GeoBoundingBoxQueryBuilderTests extends AbstractQueryTestCase<GeoBo
assertEquals(json, GeoExecType.MEMORY, parsed.type());
}
public void testFromJsonCoerceIsDeprecated() throws IOException {
String json =
"{\n" +
" \"geo_bounding_box\" : {\n" +
" \"pin.location\" : {\n" +
" \"top_left\" : [ -74.1, 40.73 ],\n" +
" \"bottom_right\" : [ -71.12, 40.01 ]\n" +
" },\n" +
" \"coerce\" : true,\n" +
" \"type\" : \"MEMORY\",\n" +
" \"ignore_unmapped\" : false,\n" +
" \"boost\" : 1.0\n" +
" }\n" +
"}";
parseQuery(json);
assertWarnings("Deprecated field [coerce] used, replaced by [validation_method]");
}
public void testFromJsonIgnoreMalformedIsDeprecated() throws IOException {
String json =
"{\n" +
" \"geo_bounding_box\" : {\n" +
" \"pin.location\" : {\n" +
" \"top_left\" : [ -74.1, 40.73 ],\n" +
" \"bottom_right\" : [ -71.12, 40.01 ]\n" +
" },\n" +
" \"ignore_malformed\" : true,\n" +
" \"type\" : \"MEMORY\",\n" +
" \"ignore_unmapped\" : false,\n" +
" \"boost\" : 1.0\n" +
" }\n" +
"}";
parseQuery(json);
assertWarnings("Deprecated field [ignore_malformed] used, replaced by [validation_method]");
}
@Override
public void testMustRewrite() throws IOException {
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);

View File

@ -316,56 +316,6 @@ public class GeoDistanceQueryBuilderTests extends AbstractQueryTestCase<GeoDista
assertEquals(json, 12000.0, parsed.distance(), 0.0001);
}
public void testOptimizeBboxIsDeprecated() throws IOException {
String json =
"{\n" +
" \"geo_distance\" : {\n" +
" \"pin.location\" : [ -70.0, 40.0 ],\n" +
" \"distance\" : 12000.0,\n" +
" \"distance_type\" : \"arc\",\n" +
" \"optimize_bbox\" : \"memory\",\n" +
" \"validation_method\" : \"STRICT\",\n" +
" \"ignore_unmapped\" : false,\n" +
" \"boost\" : 1.0\n" +
" }\n" +
"}";
parseQuery(json);
assertWarnings("Deprecated field [optimize_bbox] used, replaced by [no replacement: " +
"`optimize_bbox` is no longer supported due to recent improvements]");
}
public void testFromCoerceIsDeprecated() throws IOException {
String json =
"{\n" +
" \"geo_distance\" : {\n" +
" \"pin.location\" : [ -70.0, 40.0 ],\n" +
" \"distance\" : 12000.0,\n" +
" \"distance_type\" : \"arc\",\n" +
" \"coerce\" : true,\n" +
" \"ignore_unmapped\" : false,\n" +
" \"boost\" : 1.0\n" +
" }\n" +
"}";
parseQuery(json);
assertWarnings("Deprecated field [coerce] used, replaced by [validation_method]");
}
public void testFromJsonIgnoreMalformedIsDeprecated() throws IOException {
String json =
"{\n" +
" \"geo_distance\" : {\n" +
" \"pin.location\" : [ -70.0, 40.0 ],\n" +
" \"distance\" : 12000.0,\n" +
" \"distance_type\" : \"arc\",\n" +
" \"ignore_malformed\" : true,\n" +
" \"ignore_unmapped\" : false,\n" +
" \"boost\" : 1.0\n" +
" }\n" +
"}";
parseQuery(json);
assertWarnings("Deprecated field [ignore_malformed] used, replaced by [validation_method]");
}
@Override
public void testMustRewrite() throws IOException {
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);

View File

@ -124,25 +124,6 @@ public class GeoPolygonQueryBuilderTests extends AbstractQueryTestCase<GeoPolygo
assertEquals("too few points defined for geo_polygon query", e.getMessage());
}
public void testDeprecatedXContent() throws IOException {
XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint();
builder.startObject();
builder.startObject("geo_polygon");
builder.startObject(GEO_POINT_FIELD_NAME);
builder.startArray("points");
builder.value("0,0");
builder.value("0,90");
builder.value("90,90");
builder.value("90,0");
builder.endArray();
builder.endObject();
builder.field("normalize", true); // deprecated
builder.endObject();
builder.endObject();
parseQuery(builder.string());
assertWarnings("Deprecated field [normalize] used, replaced by [validation_method]");
}
public void testParsingAndToQueryParsingExceptions() throws IOException {
String[] brokenFiles = new String[]{
"/org/elasticsearch/index/query/geo_polygon_exception_1.json",
@ -254,37 +235,6 @@ public class GeoPolygonQueryBuilderTests extends AbstractQueryTestCase<GeoPolygo
assertEquals(json, 4, parsed.points().size());
}
public void testFromJsonIgnoreMalformedDeprecated() throws IOException {
String json =
"{\n" +
" \"geo_polygon\" : {\n" +
" \"person.location\" : {\n" +
" \"points\" : [ [ -70.0, 40.0 ], [ -80.0, 30.0 ], [ -90.0, 20.0 ], [ -70.0, 40.0 ] ]\n" +
" },\n" +
" \"ignore_malformed\" : false,\n" +
" \"boost\" : 1.0\n" +
" }\n" +
"}";
parseQuery(json);
assertWarnings("Deprecated field [ignore_malformed] used, replaced by [validation_method]");
}
public void testFromJsonCoerceDeprecated() throws IOException {
String json =
"{\n" +
" \"geo_polygon\" : {\n" +
" \"person.location\" : {\n" +
" \"points\" : [ [ -70.0, 40.0 ], [ -80.0, 30.0 ], [ -90.0, 20.0 ], [ -70.0, 40.0 ] ]\n" +
" },\n" +
" \"coerce\" : false,\n" +
" \"ignore_unmapped\" : false,\n" +
" \"boost\" : 1.0\n" +
" }\n" +
"}";
parseQuery(json);
assertWarnings("Deprecated field [coerce] used, replaced by [validation_method]");
}
@Override
public void testMustRewrite() throws IOException {
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);

View File

@ -146,7 +146,6 @@ public class QueryDSLDocumentationTests extends ESTestCase {
geoDistanceQuery("pin.location")
.point(40, -70)
.distance(200, DistanceUnit.KILOMETERS)
.optimizeBbox("memory") // TODO switch to geoexectype see also bounding box
.geoDistance(GeoDistance.ARC);
}

View File

@ -195,106 +195,6 @@ public class GeoDistanceSortBuilderTests extends AbstractSortTestCase<GeoDistanc
}
}
public void testReverseOptionFailsWhenNonStringField() throws IOException {
String json = "{\n" +
" \"testname\" : [ {\n" +
" \"lat\" : -6.046997540714173,\n" +
" \"lon\" : -51.94128329747579\n" +
" } ],\n" +
" \"reverse\" : true\n" +
"}";
XContentParser itemParser = createParser(JsonXContent.jsonXContent, json);
itemParser.nextToken();
QueryParseContext context = new QueryParseContext(itemParser);
try {
GeoDistanceSortBuilder.fromXContent(context, "");
fail("adding reverse sorting option should fail with an exception");
} catch (ParsingException e) {
assertEquals("Only geohashes of type string supported for field [reverse]", e.getMessage());
}
}
public void testReverseOptionFailsWhenStringFieldButResetting() throws IOException {
String json = "{\n" +
" \"testname\" : [ {\n" +
" \"lat\" : -6.046997540714173,\n" +
" \"lon\" : -51.94128329747579\n" +
" } ],\n" +
" \"reverse\" : \"true\"\n" +
"}";
XContentParser itemParser = createParser(JsonXContent.jsonXContent, json);
itemParser.nextToken();
QueryParseContext context = new QueryParseContext(itemParser);
try {
GeoDistanceSortBuilder.fromXContent(context, "");
fail("adding reverse sorting option should fail with an exception");
} catch (ParsingException e) {
assertEquals("Trying to reset fieldName to [reverse], already set to [testname].", e.getMessage());
}
}
public void testReverseOptionFailsBuildWhenInvalidGeoHashString() throws IOException {
String json = "{\n" +
" \"reverse\" : \"false\"\n" +
"}";
XContentParser itemParser = createParser(JsonXContent.jsonXContent, json);
itemParser.nextToken();
QueryParseContext context = new QueryParseContext(itemParser);
try {
GeoDistanceSortBuilder item = GeoDistanceSortBuilder.fromXContent(context, "");
item.validation(GeoValidationMethod.STRICT);
item.build(createMockShardContext());
fail("adding reverse sorting option should fail with an exception");
} catch (ElasticsearchParseException e) {
assertEquals("illegal latitude value [269.384765625] for [GeoDistanceSort] for field [reverse].", e.getMessage());
}
}
public void testCoerceIsDeprecated() throws IOException {
String json = "{\n" +
" \"testname\" : [ {\n" +
" \"lat\" : -6.046997540714173,\n" +
" \"lon\" : -51.94128329747579\n" +
" } ],\n" +
" \"unit\" : \"m\",\n" +
" \"distance_type\" : \"arc\",\n" +
" \"mode\" : \"MAX\",\n" +
" \"coerce\" : true\n" +
"}";
XContentParser itemParser = createParser(JsonXContent.jsonXContent, json);
itemParser.nextToken();
QueryParseContext context = new QueryParseContext(itemParser);
GeoDistanceSortBuilder.fromXContent(context, "");
assertWarnings("Deprecated field [coerce] used, replaced by [validation_method]");
}
public void testIgnoreMalformedIsDeprecated() throws IOException {
String json = "{\n" +
" \"testname\" : [ {\n" +
" \"lat\" : -6.046997540714173,\n" +
" \"lon\" : -51.94128329747579\n" +
" } ],\n" +
" \"unit\" : \"m\",\n" +
" \"distance_type\" : \"arc\",\n" +
" \"mode\" : \"MAX\",\n" +
" \"ignore_malformed\" : true\n" +
"}";
XContentParser itemParser = createParser(JsonXContent.jsonXContent, json);
itemParser.nextToken();
QueryParseContext context = new QueryParseContext(itemParser);
GeoDistanceSortBuilder.fromXContent(context, "");
assertWarnings("Deprecated field [ignore_malformed] used, replaced by [validation_method]");
}
public void testSortModeSumIsRejectedInJSON() throws IOException {
String json = "{\n" +
" \"testname\" : [ {\n" +

View File

@ -35,8 +35,15 @@
a regex as `max_determinized_states` instead of the typo
`max_determined_states`.
* For `geo_distance` queries, sorting, and aggregations the `sloppy_arc` and `factor` options
have been removed from the `distance_type` parameter.
* For `geo_distance` queries, sorting, and aggregations the `sloppy_arc` option
has been removed from the `distance_type` parameter.
* The `geo_distance_range` query, which was deprecated in 5.0, has been removed.
* The `optimize_bbox` parameter has been removed from `geo_distance` queries.
* The `ignore_malformed` and `coerce` parameters have been removed from
`geo_bounding_box`, `geo_polygon`, and `geo_distance` queries.
==== Search shards API