elasticsearch/docs/reference/migration/migrate_8_0/java.asciidoc
Christoph Büscher 1597f69e44
Make Fuzziness reject illegal values earlier (#33511)
The current java implementation of Fuzziness leaves a lot of room for
initializing it with illegal values that either cause errors later when the
queries reach the shards where they are executed or values that are silently
ignored in favour of defaults. We should instead tighten the java implementation
of the class so that we only accept supported values. Currently those are
numeric values representing the edit distances 0, 1 and 2, optionally also as
float or string, and the "AUTO" fuzziness, which can come in a cusomizable
variant that allows specifying two value that define the positions in a term
where the AUTO option increases the allowed edit distance.

This change removes several redundant ways of object construction and adds input
validation to the remaining ones. Java users should either use one of the
predefined constants or use the static factory methods `fromEdits(int)` or
`fromString(String)` to create instances of the class, while other ctors are
hidden. This allows for instance control, e.g. returning one of the constants
when creating instances from an integer value.

Previously the class would accept any positive integer value and any float
value, while in effect the maximum allowed edit distance was capped at 2 in
practice. These values while throw an error now, as will any other String value
other than "AUTO" that where previously accepted but led to numeric exceptions
when the query was executed.
2019-04-05 10:35:35 +02:00

20 lines
938 B
Text

[float]
[[breaking_80_java_changes]]
=== Java API changes
[float]
==== Changes to Fuzziness
To create `Fuzziness` instances, use the `fromString` and `fromEdits` method
instead of the `build` method that used to accept both Strings and numeric
values. Several fuzziness setters on query builders (e.g.
MatchQueryBuilder#fuzziness) now accept only a `Fuzziness`instance instead of
an Object. You should preferably use the available constants (e.g.
Fuzziness.ONE, Fuzziness.AUTO) or build your own instance using the above
mentioned factory methods.
Fuzziness used to be lenient when it comes to parsing arbitrary numeric values
while silently truncating them to one of the three allowed edit distances 0, 1
or 2. This leniency is now removed and the class will throw errors when trying
to construct an instance with another value (e.g. floats like 1.3 used to get
accepted but truncated to 1). You should use one of the allowed values.