Deprecate coerce/ignore_malformed for GeoPolygonQueryBuilder

Includes update to parsing code, tests, migration docs and reference
docs.
This commit is contained in:
Isabel Drost-Fromm 2016-04-28 13:56:50 +02:00
parent 78ff4f52d6
commit 5306de3ce3
4 changed files with 43 additions and 10 deletions

View File

@ -54,8 +54,10 @@ public class GeoPolygonQueryBuilder extends AbstractQueryBuilder<GeoPolygonQuery
*/ */
public static final boolean DEFAULT_IGNORE_UNMAPPED = false; public static final boolean DEFAULT_IGNORE_UNMAPPED = false;
private static final ParseField COERCE_FIELD = new ParseField("coerce", "normalize"); private static final ParseField COERCE_FIELD = new ParseField("coerce", "normalize")
private static final ParseField IGNORE_MALFORMED_FIELD = new ParseField("ignore_malformed"); .withAllDeprecated("use validation_method instead");
private static final ParseField IGNORE_MALFORMED_FIELD = new ParseField("ignore_malformed")
.withAllDeprecated("use validation_method instead");
private static final ParseField VALIDATION_METHOD = new ParseField("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 POINTS_FIELD = new ParseField("points");
private static final ParseField IGNORE_UNMAPPED_FIELD = new ParseField("ignore_unmapped"); private static final ParseField IGNORE_UNMAPPED_FIELD = new ParseField("ignore_unmapped");
@ -232,9 +234,7 @@ public class GeoPolygonQueryBuilder extends AbstractQueryBuilder<GeoPolygonQuery
builder.endArray(); builder.endArray();
builder.endObject(); builder.endObject();
builder.field(COERCE_FIELD.getPreferredName(), GeoValidationMethod.isCoerce(validationMethod)); builder.field(VALIDATION_METHOD.getPreferredName(), validationMethod);
builder.field(IGNORE_MALFORMED_FIELD.getPreferredName(),
GeoValidationMethod.isIgnoreMalformed(validationMethod));
builder.field(IGNORE_UNMAPPED_FIELD.getPreferredName(), ignoreUnmapped); builder.field(IGNORE_UNMAPPED_FIELD.getPreferredName(), ignoreUnmapped);
printBoostAndQueryName(builder); printBoostAndQueryName(builder);

View File

@ -207,7 +207,7 @@ public class GeoPolygonQueryBuilderTests extends AbstractQueryTestCase<GeoPolygo
parseQuery(builder.string()); parseQuery(builder.string());
fail("normalize is deprecated"); fail("normalize is deprecated");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
assertEquals("Deprecated field [normalize] used, expected [coerce] instead", ex.getMessage()); assertEquals("Deprecated field [normalize] used, replaced by [use validation_method instead]", ex.getMessage());
} }
} }
@ -342,8 +342,7 @@ public class GeoPolygonQueryBuilderTests extends AbstractQueryTestCase<GeoPolygo
" \"person.location\" : {\n" + " \"person.location\" : {\n" +
" \"points\" : [ [ -70.0, 40.0 ], [ -80.0, 30.0 ], [ -90.0, 20.0 ], [ -70.0, 40.0 ] ]\n" + " \"points\" : [ [ -70.0, 40.0 ], [ -80.0, 30.0 ], [ -90.0, 20.0 ], [ -70.0, 40.0 ] ]\n" +
" },\n" + " },\n" +
" \"coerce\" : false,\n" + " \"validation_method\" : \"STRICT\",\n" +
" \"ignore_malformed\" : false,\n" +
" \"ignore_unmapped\" : false,\n" + " \"ignore_unmapped\" : false,\n" +
" \"boost\" : 1.0\n" + " \"boost\" : 1.0\n" +
" }\n" + " }\n" +
@ -353,6 +352,38 @@ public class GeoPolygonQueryBuilderTests extends AbstractQueryTestCase<GeoPolygo
assertEquals(json, 4, parsed.points().size()); 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" +
"}";
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> parseQuery(json));
assertTrue(e.getMessage().startsWith("Deprecated field "));
}
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" +
"}";
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> parseQuery(json));
assertTrue(e.getMessage().startsWith("Deprecated field "));
}
@Override @Override
public void testMustRewrite() throws IOException { public void testMustRewrite() throws IOException {
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0); assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);

View File

@ -126,6 +126,7 @@ in favour of `query` and `no_match_query`.
* The `exists` query will now fail if the `_field_names` field is disabled. * The `exists` query will now fail if the `_field_names` field is disabled.
* Deprecated support for the coerce, normalize, ignore_malformed parameters in GeoPolygonQuery. Use parameter validation_method instead.
==== Top level `filter` parameter ==== Top level `filter` parameter

View File

@ -34,8 +34,9 @@ points. Here is an example:
|Option |Description |Option |Description
|`_name` |Optional name field to identify the filter |`_name` |Optional name field to identify the filter
|`ignore_malformed` |Set to `true` to accept geo points with invalid latitude or |`validation_method` |Set to `IGNORE_MALFORMED` to accept geo points with
longitude (default is `false`). invalid latitude or longitude, `COERCE` to try and infer correct latitude
or longitude, or `STRICT` (default is `STRICT`).
|======================================================================= |=======================================================================
[float] [float]