Skip to content

Commit 6d7c993

Browse files
Merge remote-tracking branch 'elastic/master' into eventually-consistent-mock-repo
2 parents 8713682 + 1597f69 commit 6d7c993

File tree

38 files changed

+392
-316
lines changed

38 files changed

+392
-316
lines changed

benchmarks/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ dependencies {
3939
runtime 'org.apache.commons:commons-math3:3.2'
4040
}
4141

42-
compileJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked,-processing"
42+
compileJava.options.compilerArgs << "-Xlint:-cast,-rawtypes,-unchecked,-processing"
4343
// enable the JMH's BenchmarkProcessor to generate the final benchmark classes
4444
// needs to be added separately otherwise Gradle will quote it and javac will fail
4545
compileJava.options.compilerArgs.addAll(["-processor", "org.openjdk.jmh.generators.BenchmarkProcessor"])

buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ class BuildPlugin implements Plugin<Project> {
752752
*/
753753
// don't even think about passing args with -J-xxx, oracle will ask you to submit a bug report :)
754754
// fail on all javac warnings
755-
options.compilerArgs << '-Werror' << '-Xlint:all,-path,-serial,-options,-deprecation' << '-Xdoclint:all' << '-Xdoclint:-missing'
755+
options.compilerArgs << '-Werror' << '-Xlint:all,-path,-serial,-options,-deprecation,-try' << '-Xdoclint:all' << '-Xdoclint:-missing'
756756

757757
// either disable annotation processor completely (default) or allow to enable them if an annotation processor is explicitly defined
758758
if (options.compilerArgs.contains("-processor") == false) {

client/client-benchmark-noop-api-plugin/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ assemble.enabled = false
3333
dependencyLicenses.enabled = false
3434
dependenciesInfo.enabled = false
3535

36-
compileJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked"
36+
compileJava.options.compilerArgs << "-Xlint:-cast,-rawtypes,-unchecked"
3737

3838
// no unit tests
3939
unitTest.enabled = false

docs/reference/mapping/types/dense-vector.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ experimental[]
55

66
A `dense_vector` field stores dense vectors of float values.
77
The maximum number of dimensions that can be in a vector should
8-
not exceed 500. The number of dimensions can be
8+
not exceed 1024. The number of dimensions can be
99
different across documents. A `dense_vector` field is
1010
a single-valued field.
1111

docs/reference/mapping/types/sparse-vector.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ experimental[]
55

66
A `sparse_vector` field stores sparse vectors of float values.
77
The maximum number of dimensions that can be in a vector should
8-
not exceed 500. The number of dimensions can be
8+
not exceed 1024. The number of dimensions can be
99
different across documents. A `sparse_vector` field is
1010
a single-valued field.
1111

docs/reference/migration/migrate_8_0.asciidoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ coming[8.0.0]
1616
* <<breaking_80_mappings_changes>>
1717
* <<breaking_80_snapshots_changes>>
1818
* <<breaking_80_security_changes>>
19+
* <<breaking_80_java_changes>>
1920

2021
//NOTE: The notable-breaking-changes tagged regions are re-used in the
2122
//Installation and Upgrade Guide
@@ -43,3 +44,4 @@ include::migrate_8_0/discovery.asciidoc[]
4344
include::migrate_8_0/mappings.asciidoc[]
4445
include::migrate_8_0/snapshots.asciidoc[]
4546
include::migrate_8_0/security.asciidoc[]
47+
include::migrate_8_0/java.asciidoc[]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[float]
2+
[[breaking_80_java_changes]]
3+
=== Java API changes
4+
5+
[float]
6+
==== Changes to Fuzziness
7+
8+
To create `Fuzziness` instances, use the `fromString` and `fromEdits` method
9+
instead of the `build` method that used to accept both Strings and numeric
10+
values. Several fuzziness setters on query builders (e.g.
11+
MatchQueryBuilder#fuzziness) now accept only a `Fuzziness`instance instead of
12+
an Object. You should preferably use the available constants (e.g.
13+
Fuzziness.ONE, Fuzziness.AUTO) or build your own instance using the above
14+
mentioned factory methods.
15+
16+
Fuzziness used to be lenient when it comes to parsing arbitrary numeric values
17+
while silently truncating them to one of the three allowed edit distances 0, 1
18+
or 2. This leniency is now removed and the class will throw errors when trying
19+
to construct an instance with another value (e.g. floats like 1.3 used to get
20+
accepted but truncated to 1). You should use one of the allowed values.

modules/transport-netty4/build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ esplugin {
2929
hasClientJar = true
3030
}
3131

32-
compileJava.options.compilerArgs << "-Xlint:-try"
33-
compileTestJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked"
32+
compileTestJava.options.compilerArgs << "-Xlint:-cast,-rawtypes,-unchecked"
3433

3534
dependencies {
3635
// network stack

server/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ if (isEclipse) {
151151
}
152152
}
153153

154-
compileJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked"
155-
compileTestJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked"
154+
compileJava.options.compilerArgs << "-Xlint:-cast,-rawtypes,-unchecked"
155+
compileTestJava.options.compilerArgs << "-Xlint:-cast,-rawtypes,-unchecked"
156156

157157
forbiddenPatterns {
158158
exclude '**/*.json'

server/src/main/java/org/elasticsearch/action/resync/TransportResyncReplicationAction.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.elasticsearch.cluster.action.shard.ShardStateAction;
2929
import org.elasticsearch.cluster.block.ClusterBlockLevel;
3030
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
31-
import org.elasticsearch.cluster.node.DiscoveryNode;
3231
import org.elasticsearch.cluster.routing.ShardRouting;
3332
import org.elasticsearch.cluster.service.ClusterService;
3433
import org.elasticsearch.common.inject.Inject;
@@ -73,14 +72,6 @@ protected ReplicationOperation.Replicas newReplicasProxy(long primaryTerm) {
7372
return new ResyncActionReplicasProxy(primaryTerm);
7473
}
7574

76-
@Override
77-
protected void sendReplicaRequest(
78-
final ConcreteReplicaRequest<ResyncReplicationRequest> replicaRequest,
79-
final DiscoveryNode node,
80-
final ActionListener<ReplicationOperation.ReplicaResponse> listener) {
81-
super.sendReplicaRequest(replicaRequest, node, listener);
82-
}
83-
8475
@Override
8576
protected ClusterBlockLevel globalBlockLevel() {
8677
// resync should never be blocked because it's an internal action

server/src/main/java/org/elasticsearch/action/support/replication/TransportReplicationAction.java

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ public void onFailure(Exception e) {
618618
}
619619
}
620620

621-
protected IndexShard getIndexShard(final ShardId shardId) {
621+
private IndexShard getIndexShard(final ShardId shardId) {
622622
IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
623623
return indexService.getShard(shardId.id());
624624
}
@@ -1044,7 +1044,12 @@ public void performOn(
10441044
}
10451045
final ConcreteReplicaRequest<ReplicaRequest> replicaRequest = new ConcreteReplicaRequest<>(
10461046
request, replica.allocationId().getId(), primaryTerm, globalCheckpoint, maxSeqNoOfUpdatesOrDeletes);
1047-
sendReplicaRequest(replicaRequest, node, listener);
1047+
final ActionListenerResponseHandler<ReplicaResponse> handler = new ActionListenerResponseHandler<>(listener, in -> {
1048+
ReplicaResponse replicaResponse = new ReplicaResponse();
1049+
replicaResponse.readFrom(in);
1050+
return replicaResponse;
1051+
});
1052+
transportService.sendRequest(node, transportReplicaAction, replicaRequest, transportOptions, handler);
10481053
}
10491054

10501055
@Override
@@ -1066,25 +1071,6 @@ public void markShardCopyAsStaleIfNeeded(ShardId shardId, String allocationId, A
10661071
}
10671072
}
10681073

1069-
/**
1070-
* Sends the specified replica request to the specified node.
1071-
*
1072-
* @param replicaRequest the replica request
1073-
* @param node the node to send the request to
1074-
* @param listener callback for handling the response or failure
1075-
*/
1076-
protected void sendReplicaRequest(
1077-
final ConcreteReplicaRequest<ReplicaRequest> replicaRequest,
1078-
final DiscoveryNode node,
1079-
final ActionListener<ReplicationOperation.ReplicaResponse> listener) {
1080-
final ActionListenerResponseHandler<ReplicaResponse> handler = new ActionListenerResponseHandler<>(listener, in -> {
1081-
ReplicaResponse replicaResponse = new ReplicaResponse();
1082-
replicaResponse.readFrom(in);
1083-
return replicaResponse;
1084-
});
1085-
transportService.sendRequest(node, transportReplicaAction, replicaRequest, transportOptions, handler);
1086-
}
1087-
10881074
/** a wrapper class to encapsulate a request when being sent to a specific allocation id **/
10891075
public static class ConcreteShardRequest<R extends TransportRequest> extends TransportRequest {
10901076

server/src/main/java/org/elasticsearch/common/unit/Fuzziness.java

Lines changed: 74 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import org.elasticsearch.ElasticsearchParseException;
2222
import org.elasticsearch.common.ParseField;
23+
import org.elasticsearch.common.Strings;
2324
import org.elasticsearch.common.io.stream.StreamInput;
2425
import org.elasticsearch.common.io.stream.StreamOutput;
2526
import org.elasticsearch.common.io.stream.Writeable;
@@ -38,41 +39,73 @@
3839
*/
3940
public final class Fuzziness implements ToXContentFragment, Writeable {
4041

41-
public static final String X_FIELD_NAME = "fuzziness";
42-
public static final Fuzziness ZERO = new Fuzziness(0);
43-
public static final Fuzziness ONE = new Fuzziness(1);
44-
public static final Fuzziness TWO = new Fuzziness(2);
45-
public static final Fuzziness AUTO = new Fuzziness("AUTO");
42+
static final String X_FIELD_NAME = "fuzziness";
4643
public static final ParseField FIELD = new ParseField(X_FIELD_NAME);
47-
private static final int DEFAULT_LOW_DISTANCE = 3;
48-
private static final int DEFAULT_HIGH_DISTANCE = 6;
44+
45+
public static final Fuzziness ZERO = new Fuzziness("0");
46+
public static final Fuzziness ONE = new Fuzziness("1");
47+
public static final Fuzziness TWO = new Fuzziness("2");
48+
public static final Fuzziness AUTO = new Fuzziness("AUTO");
49+
50+
static final int DEFAULT_LOW_DISTANCE = 3;
51+
static final int DEFAULT_HIGH_DISTANCE = 6;
4952

5053
private final String fuzziness;
5154
private int lowDistance = DEFAULT_LOW_DISTANCE;
5255
private int highDistance = DEFAULT_HIGH_DISTANCE;
5356

54-
private Fuzziness(int fuzziness) {
55-
if (fuzziness != 0 && fuzziness != 1 && fuzziness != 2) {
56-
throw new IllegalArgumentException("Valid edit distances are [0, 1, 2] but was [" + fuzziness + "]");
57-
}
58-
this.fuzziness = Integer.toString(fuzziness);
57+
private Fuzziness(String fuzziness) {
58+
this.fuzziness = fuzziness;
5959
}
6060

61-
private Fuzziness(String fuzziness) {
62-
if (fuzziness == null || fuzziness.isEmpty()) {
63-
throw new IllegalArgumentException("fuzziness can't be null!");
61+
/**
62+
* Creates a {@link Fuzziness} instance from an edit distance. The value must be one of {@code [0, 1, 2]}
63+
* Note: Using this method only makes sense if the field you are applying Fuzziness to is some sort of string.
64+
* @throws IllegalArgumentException if the edit distance is not in [0, 1, 2]
65+
*/
66+
public static Fuzziness fromEdits(int edits) {
67+
switch (edits) {
68+
case 0: return Fuzziness.ZERO;
69+
case 1: return Fuzziness.ONE;
70+
case 2: return Fuzziness.TWO;
71+
default:
72+
throw new IllegalArgumentException("Valid edit distances are [0, 1, 2] but was [" + edits + "]");
6473
}
65-
this.fuzziness = fuzziness.toUpperCase(Locale.ROOT);
6674
}
6775

68-
private Fuzziness(String fuzziness, int lowDistance, int highDistance) {
69-
this(fuzziness);
70-
if (lowDistance < 0 || highDistance < 0 || lowDistance > highDistance) {
71-
throw new IllegalArgumentException("fuzziness wrongly configured, must be: lowDistance > 0, highDistance" +
72-
" > 0 and lowDistance <= highDistance ");
76+
/**
77+
* Creates a {@link Fuzziness} instance from a String representation. This can
78+
* either be an edit distance where the value must be one of
79+
* {@code ["0", "1", "2"]} or "AUTO" for a fuzziness that depends on the term
80+
* length. Using the "AUTO" fuzziness, you can optionally supply low and high
81+
* distance arguments in the format {@code "AUTO:[low],[high]"}. See the query
82+
* DSL documentation for more information about how these values affect the
83+
* fuzziness value.
84+
* Note: Using this method only makes sense if the field you
85+
* are applying Fuzziness to is some sort of string.
86+
*/
87+
public static Fuzziness fromString(String fuzzinessString) {
88+
if (Strings.isEmpty(fuzzinessString)) {
89+
throw new IllegalArgumentException("fuzziness cannot be null or empty.");
90+
}
91+
String upperCase = fuzzinessString.toUpperCase(Locale.ROOT);
92+
// check if it is one of the "AUTO" variants
93+
if (upperCase.equals("AUTO")) {
94+
return Fuzziness.AUTO;
95+
} else if (upperCase.startsWith("AUTO:")) {
96+
return parseCustomAuto(upperCase);
97+
} else {
98+
// should be a float or int representing a valid edit distance, otherwise throw error
99+
try {
100+
float parsedFloat = Float.parseFloat(upperCase);
101+
if (parsedFloat % 1 > 0) {
102+
throw new IllegalArgumentException("fuzziness needs to be one of 0.0, 1.0 or 2.0 but was " + parsedFloat);
103+
}
104+
return fromEdits((int) parsedFloat);
105+
} catch (NumberFormatException e) {
106+
throw new IllegalArgumentException("fuzziness cannot be [" + fuzzinessString + "].", e);
107+
}
73108
}
74-
this.lowDistance = lowDistance;
75-
this.highDistance = highDistance;
76109
}
77110

78111
/**
@@ -101,39 +134,23 @@ public void writeTo(StreamOutput out) throws IOException {
101134
}
102135
}
103136

104-
/**
105-
* Creates a {@link Fuzziness} instance from an edit distance. The value must be one of {@code [0, 1, 2]}
106-
*
107-
* Note: Using this method only makes sense if the field you are applying Fuzziness to is some sort of string.
108-
*/
109-
public static Fuzziness fromEdits(int edits) {
110-
return new Fuzziness(edits);
111-
}
112-
113-
public static Fuzziness build(Object fuzziness) {
114-
if (fuzziness instanceof Fuzziness) {
115-
return (Fuzziness) fuzziness;
116-
}
117-
String string = fuzziness.toString();
118-
if (AUTO.asString().equalsIgnoreCase(string)) {
119-
return AUTO;
120-
} else if (string.toUpperCase(Locale.ROOT).startsWith(AUTO.asString() + ":")) {
121-
return parseCustomAuto(string);
122-
}
123-
return new Fuzziness(string);
124-
}
125-
126-
private static Fuzziness parseCustomAuto( final String string) {
127-
assert string.toUpperCase(Locale.ROOT).startsWith(AUTO.asString() + ":");
128-
String[] fuzzinessLimit = string.substring(AUTO.asString().length() + 1).split(",");
137+
private static Fuzziness parseCustomAuto(final String fuzzinessString) {
138+
assert fuzzinessString.toUpperCase(Locale.ROOT).startsWith(AUTO.asString() + ":");
139+
String[] fuzzinessLimit = fuzzinessString.substring(AUTO.asString().length() + 1).split(",");
129140
if (fuzzinessLimit.length == 2) {
130141
try {
131142
int lowerLimit = Integer.parseInt(fuzzinessLimit[0]);
132143
int highLimit = Integer.parseInt(fuzzinessLimit[1]);
133-
return new Fuzziness("AUTO", lowerLimit, highLimit);
144+
if (lowerLimit < 0 || highLimit < 0 || lowerLimit > highLimit) {
145+
throw new ElasticsearchParseException("fuzziness wrongly configured [{}]. Must be 0 < lower value <= higher value.",
146+
fuzzinessString);
147+
}
148+
Fuzziness fuzziness = new Fuzziness("AUTO");
149+
fuzziness.lowDistance = lowerLimit;
150+
fuzziness.highDistance = highLimit;
151+
return fuzziness;
134152
} catch (NumberFormatException e) {
135-
throw new ElasticsearchParseException("failed to parse [{}] as a \"auto:int,int\"", e,
136-
string);
153+
throw new ElasticsearchParseException("failed to parse [{}] as a \"auto:int,int\"", e, fuzzinessString);
137154
}
138155
} else {
139156
throw new ElasticsearchParseException("failed to find low and high distance values");
@@ -144,29 +161,9 @@ public static Fuzziness parse(XContentParser parser) throws IOException {
144161
XContentParser.Token token = parser.currentToken();
145162
switch (token) {
146163
case VALUE_STRING:
164+
return fromString(parser.text());
147165
case VALUE_NUMBER:
148-
final String fuzziness = parser.text();
149-
if (AUTO.asString().equalsIgnoreCase(fuzziness)) {
150-
return AUTO;
151-
} else if (fuzziness.toUpperCase(Locale.ROOT).startsWith(AUTO.asString() + ":")) {
152-
return parseCustomAuto(fuzziness);
153-
}
154-
try {
155-
final int minimumSimilarity = Integer.parseInt(fuzziness);
156-
switch (minimumSimilarity) {
157-
case 0:
158-
return ZERO;
159-
case 1:
160-
return ONE;
161-
case 2:
162-
return TWO;
163-
default:
164-
return build(fuzziness);
165-
}
166-
} catch (NumberFormatException ex) {
167-
return build(fuzziness);
168-
}
169-
166+
return fromEdits(parser.intValue());
170167
default:
171168
throw new IllegalArgumentException("Can't parse fuzziness on token: [" + token + "]");
172169
}
@@ -200,7 +197,7 @@ public float asFloat() {
200197
if (this.equals(AUTO) || isAutoWithCustomValues()) {
201198
return 1f;
202199
}
203-
return Float.parseFloat(fuzziness.toString());
200+
return Float.parseFloat(fuzziness);
204201
}
205202

206203
private int termLen(String text) {
@@ -209,13 +206,13 @@ private int termLen(String text) {
209206

210207
public String asString() {
211208
if (isAutoWithCustomValues()) {
212-
return fuzziness.toString() + ":" + lowDistance + "," + highDistance;
209+
return fuzziness + ":" + lowDistance + "," + highDistance;
213210
}
214-
return fuzziness.toString();
211+
return fuzziness;
215212
}
216213

217214
private boolean isAutoWithCustomValues() {
218-
return fuzziness.startsWith("AUTO") && (lowDistance != DEFAULT_LOW_DISTANCE ||
215+
return fuzziness.equals("AUTO") && (lowDistance != DEFAULT_LOW_DISTANCE ||
219216
highDistance != DEFAULT_HIGH_DISTANCE);
220217
}
221218

server/src/main/java/org/elasticsearch/index/query/MatchBoolPrefixQueryBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ public String minimumShouldMatch() {
161161
}
162162

163163
/** Sets the fuzziness used when evaluated to a fuzzy query type. Defaults to "AUTO". */
164-
public MatchBoolPrefixQueryBuilder fuzziness(Object fuzziness) {
165-
this.fuzziness = Fuzziness.build(fuzziness);
164+
public MatchBoolPrefixQueryBuilder fuzziness(Fuzziness fuzziness) {
165+
this.fuzziness = fuzziness;
166166
return this;
167167
}
168168

0 commit comments

Comments
 (0)