Skip to content

Commit 9c657d7

Browse files
committed
Fix default indicesOptions in parsing RestoreSnapshotRequest
1 parent 1694583 commit 9c657d7

3 files changed

Lines changed: 21 additions & 5 deletions

File tree

core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ public CreateSnapshotRequest source(Map<String, Object> source) {
403403
includeGlobalState = nodeBooleanValue(entry.getValue(), "include_global_state");
404404
}
405405
}
406-
indicesOptions(IndicesOptions.fromMap(source, IndicesOptions.strictExpandOpen()));
406+
indicesOptions(IndicesOptions.fromMap(source, indicesOptions));
407407
return this;
408408
}
409409

core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ public Settings indexSettings() {
505505
* @param source restore definition
506506
* @return this request
507507
*/
508+
@SuppressWarnings("unchecked")
508509
public RestoreSnapshotRequest source(Map<String, Object> source) {
509510
for (Map.Entry<String, Object> entry : source.entrySet()) {
510511
String name = entry.getKey();
@@ -558,7 +559,7 @@ public RestoreSnapshotRequest source(Map<String, Object> source) {
558559
}
559560
}
560561
}
561-
indicesOptions(IndicesOptions.fromMap((Map<String, Object>) source, IndicesOptions.lenientExpandOpen()));
562+
indicesOptions(IndicesOptions.fromMap(source, indicesOptions));
562563
return this;
563564
}
564565

core/src/test/java/org/elasticsearch/snapshots/SnapshotRequestsTests.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void testRestoreSnapshotRequestParsing() throws IOException {
3737

3838
XContentBuilder builder = jsonBuilder().startObject();
3939

40-
if(randomBoolean()) {
40+
if (randomBoolean()) {
4141
builder.field("indices", "foo,bar,baz");
4242
} else {
4343
builder.startArray("indices");
@@ -76,6 +76,10 @@ public void testRestoreSnapshotRequestParsing() throws IOException {
7676
builder.value("set3");
7777
builder.endArray();
7878
}
79+
boolean includeIgnoreUnavailable = randomBoolean();
80+
if (includeIgnoreUnavailable) {
81+
builder.field("ignore_unavailable", indicesOptions.ignoreUnavailable());
82+
}
7983

8084
BytesReference bytes = builder.endObject().bytes();
8185

@@ -89,15 +93,18 @@ public void testRestoreSnapshotRequestParsing() throws IOException {
8993
assertEquals(partial, request.partial());
9094
assertEquals("val1", request.settings().get("set1"));
9195
assertArrayEquals(request.ignoreIndexSettings(), new String[]{"set2", "set3"});
92-
96+
boolean expectedIgnoreAvailable = includeIgnoreUnavailable
97+
? indicesOptions.ignoreUnavailable()
98+
: IndicesOptions.strictExpandOpen().ignoreUnavailable();
99+
assertEquals(expectedIgnoreAvailable, request.indicesOptions().ignoreUnavailable());
93100
}
94101

95102
public void testCreateSnapshotRequestParsing() throws IOException {
96103
CreateSnapshotRequest request = new CreateSnapshotRequest("test-repo", "test-snap");
97104

98105
XContentBuilder builder = jsonBuilder().startObject();
99106

100-
if(randomBoolean()) {
107+
if (randomBoolean()) {
101108
builder.field("indices", "foo,bar,baz");
102109
} else {
103110
builder.startArray("indices");
@@ -134,6 +141,10 @@ public void testCreateSnapshotRequestParsing() throws IOException {
134141
builder.value("set3");
135142
builder.endArray();
136143
}
144+
boolean includeIgnoreUnavailable = randomBoolean();
145+
if (includeIgnoreUnavailable) {
146+
builder.field("ignore_unavailable", indicesOptions.ignoreUnavailable());
147+
}
137148

138149
BytesReference bytes = builder.endObject().bytes();
139150

@@ -144,6 +155,10 @@ public void testCreateSnapshotRequestParsing() throws IOException {
144155
assertArrayEquals(request.indices(), new String[]{"foo", "bar", "baz"});
145156
assertEquals(partial, request.partial());
146157
assertEquals("val1", request.settings().get("set1"));
158+
boolean expectedIgnoreAvailable = includeIgnoreUnavailable
159+
? indicesOptions.ignoreUnavailable()
160+
: IndicesOptions.strictExpandOpen().ignoreUnavailable();
161+
assertEquals(expectedIgnoreAvailable, request.indicesOptions().ignoreUnavailable());
147162
}
148163

149164
}

0 commit comments

Comments
 (0)