Skip to content

Commit ac3e4a6

Browse files
Reindex remove outer level size (#43373)
This commit finalizes the work done to rename size to max_docs in reindex and update/delete by query. size is no longer supported in URL or outer level body for the 3 APIs (though size in update/delete-by-query will and has always been interpreted as scroll_size, it is not to be relied upon). Continuation of #41894 Closes #24344
1 parent 3ed3041 commit ac3e4a6

File tree

16 files changed

+45
-360
lines changed

16 files changed

+45
-360
lines changed

client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java

+7-19
Original file line numberDiff line numberDiff line change
@@ -427,11 +427,7 @@ public void testReindex() throws IOException {
427427
reindexRequest.setDestRouting("=cat");
428428
}
429429
if (randomBoolean()) {
430-
if (randomBoolean()) {
431-
reindexRequest.setMaxDocs(randomIntBetween(100, 1000));
432-
} else {
433-
reindexRequest.setSize(randomIntBetween(100, 1000));
434-
}
430+
reindexRequest.setMaxDocs(randomIntBetween(100, 1000));
435431
}
436432
if (randomBoolean()) {
437433
reindexRequest.setAbortOnVersionConflict(false);
@@ -479,13 +475,9 @@ public void testUpdateByQuery() throws IOException {
479475
expectedParams.put("routing", "=cat");
480476
}
481477
if (randomBoolean()) {
482-
int size = randomIntBetween(100, 1000);
483-
if (randomBoolean()) {
484-
updateByQueryRequest.setMaxDocs(size);
485-
} else {
486-
updateByQueryRequest.setSize(size);
487-
}
488-
expectedParams.put("max_docs", Integer.toString(size));
478+
int maxDocs = randomIntBetween(100, 1000);
479+
updateByQueryRequest.setMaxDocs(maxDocs);
480+
expectedParams.put("max_docs", Integer.toString(maxDocs));
489481
}
490482
if (randomBoolean()) {
491483
updateByQueryRequest.setAbortOnVersionConflict(false);
@@ -528,13 +520,9 @@ public void testDeleteByQuery() throws IOException {
528520
expectedParams.put("routing", "=cat");
529521
}
530522
if (randomBoolean()) {
531-
int size = randomIntBetween(100, 1000);
532-
if (randomBoolean()) {
533-
deleteByQueryRequest.setMaxDocs(size);
534-
} else {
535-
deleteByQueryRequest.setSize(size);
536-
}
537-
expectedParams.put("max_docs", Integer.toString(size));
523+
int maxDocs = randomIntBetween(100, 1000);
524+
deleteByQueryRequest.setMaxDocs(maxDocs);
525+
expectedParams.put("max_docs", Integer.toString(maxDocs));
538526
}
539527
if (randomBoolean()) {
540528
deleteByQueryRequest.setAbortOnVersionConflict(false);

docs/reference/migration/migrate_8_0/reindex.asciidoc

+15-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,18 @@ Instead, please specify the index-name without any encoding.
1212
[float]
1313
==== Removal of types
1414

15-
The `/{index}/{type}/_delete_by_query` and `/{index}/{type}/_update_by_query` REST endpoints have been removed in favour of `/{index}/_delete_by_query` and `/{index}/_update_by_query`, since indexes no longer contain types, these typed endpoints are obsolete.
15+
The `/{index}/{type}/_delete_by_query` and `/{index}/{type}/_update_by_query` REST endpoints have been removed in favour of `/{index}/_delete_by_query` and `/{index}/_update_by_query`, since indexes no longer contain types, these typed endpoints are obsolete.
16+
17+
[float]
18+
==== Removal of size parameter
19+
20+
Previously, a `_reindex` request had two different size specifications in the body:
21+
22+
- Outer level, determining the maximum number of documents to process
23+
- Inside the `source` element, determining the scroll/batch size.
24+
25+
The outer level `size` parameter has now been renamed to `max_docs` to
26+
avoid confusion and clarify its semantics.
27+
28+
Similarly, the `size` parameter has been renamed to `max_docs` for
29+
`_delete_by_query` and `_update_by_query` to keep the 3 interfaces consistent.

modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBulkByQueryRestHandler.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.elasticsearch.action.search.SearchRequest;
2424
import org.elasticsearch.common.bytes.BytesReference;
2525
import org.elasticsearch.common.settings.Settings;
26-
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
2726
import org.elasticsearch.common.xcontent.XContentBuilder;
2827
import org.elasticsearch.common.xcontent.XContentFactory;
2928
import org.elasticsearch.common.xcontent.XContentParser;
@@ -53,7 +52,7 @@ protected void parseInternalRequest(Request internal, RestRequest restRequest,
5352
SearchRequest searchRequest = internal.getSearchRequest();
5453

5554
try (XContentParser parser = extractRequestSpecificFields(restRequest, bodyConsumers)) {
56-
RestSearchAction.parseSearchRequest(searchRequest, restRequest, parser, size -> setMaxDocsFromSearchSize(internal, size));
55+
RestSearchAction.parseSearchRequest(searchRequest, restRequest, parser, size -> failOnSizeSpecified());
5756
}
5857

5958
searchRequest.source().size(restRequest.paramAsInt("scroll_size", searchRequest.source().size()));
@@ -96,8 +95,7 @@ private XContentParser extractRequestSpecificFields(RestRequest restRequest,
9695
}
9796
}
9897

99-
private void setMaxDocsFromSearchSize(Request request, int size) {
100-
LoggingDeprecationHandler.INSTANCE.usedDeprecatedName("size", "max_docs");
101-
setMaxDocsValidateIdentical(request, size);
98+
private static void failOnSizeSpecified() {
99+
throw new IllegalArgumentException("invalid parameter [size], use [max_docs] instead");
102100
}
103101
}

modules/reindex/src/test/java/org/elasticsearch/index/reindex/RoundTripTests.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,7 @@ private void randomRequest(AbstractBulkByScrollRequest<?> request) {
107107
request.getSearchRequest().indices("test");
108108
request.getSearchRequest().source().size(between(1, 1000));
109109
if (randomBoolean()) {
110-
if (randomBoolean()) {
111-
request.setMaxDocs(between(1, Integer.MAX_VALUE));
112-
} else {
113-
request.setSize(between(1, Integer.MAX_VALUE));
114-
}
110+
request.setMaxDocs(between(1, Integer.MAX_VALUE));
115111
}
116112
request.setAbortOnVersionConflict(random().nextBoolean());
117113
request.setRefresh(rarely());

modules/reindex/src/test/resources/rest-api-spec/test/delete_by_query/10_basic.yml

-46
Original file line numberDiff line numberDiff line change
@@ -279,52 +279,6 @@
279279

280280
- match: {count: 1}
281281

282-
---
283-
"Limit by size":
284-
- skip:
285-
version: " - 7.2.99"
286-
reason: "deprecation warnings only emitted on 7.3+"
287-
features: warnings
288-
289-
- do:
290-
index:
291-
index: twitter
292-
id: 1
293-
body: { "user": "kimchy" }
294-
- do:
295-
index:
296-
index: twitter
297-
id: 2
298-
body: { "user": "kimchy" }
299-
- do:
300-
indices.refresh: {}
301-
302-
- do:
303-
warnings:
304-
- Deprecated field [size] used, expected [max_docs] instead
305-
delete_by_query:
306-
index: twitter
307-
size: 1
308-
body:
309-
query:
310-
match_all: {}
311-
312-
- match: {deleted: 1}
313-
- match: {version_conflicts: 0}
314-
- match: {batches: 1}
315-
- match: {failures: []}
316-
- match: {throttled_millis: 0}
317-
- gte: { took: 0 }
318-
319-
- do:
320-
indices.refresh: {}
321-
322-
- do:
323-
count:
324-
index: twitter
325-
326-
- match: {count: 1}
327-
328282
---
329283
"Limit by size pre 7.3":
330284
- skip:

modules/reindex/src/test/resources/rest-api-spec/test/delete_by_query/20_validation.yml

-37
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,6 @@
3030
query:
3131
match_all: {}
3232

33-
---
34-
"invalid size fails":
35-
- do:
36-
index:
37-
index: test
38-
id: 1
39-
body: { "text": "test" }
40-
- do:
41-
catch: /\[max_docs\] parameter cannot be negative, found \[-4\]/
42-
delete_by_query:
43-
index: test
44-
size: -4
45-
body:
46-
query:
47-
match_all: {}
48-
4933
---
5034
"invalid max_docs fails":
5135
- skip:
@@ -66,27 +50,6 @@
6650
query:
6751
match_all: {}
6852

69-
---
70-
"both max_docs and size fails":
71-
- skip:
72-
version: " - 7.2.99"
73-
reason: "max_docs introduced in 7.3.0"
74-
75-
- do:
76-
index:
77-
index: test
78-
id: 1
79-
body: { "text": "test" }
80-
- do:
81-
catch: /\[max_docs\] set to two different values \[4\] and \[5\]/
82-
delete_by_query:
83-
index: test
84-
size: 4
85-
max_docs: 5
86-
body:
87-
query:
88-
match_all: {}
89-
9053
---
9154
"invalid scroll_size fails":
9255
- do:

modules/reindex/src/test/resources/rest-api-spec/test/reindex/20_validation.yml

+11-28
Original file line numberDiff line numberDiff line change
@@ -95,21 +95,26 @@
9595
conflicts: cat
9696

9797
---
98-
"invalid size fails":
98+
"specifying size fails":
99+
- skip:
100+
version: " - 7.99.99"
101+
reason: "size supported until 8"
102+
99103
- do:
100104
index:
101-
index: test
102-
id: 1
103-
body: { "text": "test" }
105+
index: test
106+
id: 1
107+
body: { "text": "test" }
108+
104109
- do:
105-
catch: /\[max_docs\] parameter cannot be negative, found \[-4\]/
110+
catch: /invalid parameter \[size\], use \[max_docs\] instead/
106111
reindex:
107112
body:
108113
source:
109114
index: test
110115
dest:
111116
index: dest
112-
size: -4
117+
size: 1
113118

114119
---
115120
"invalid max_docs in body fails":
@@ -153,28 +158,6 @@
153158
dest:
154159
index: dest
155160

156-
---
157-
"inconsistent max_docs and size fails":
158-
- skip:
159-
version: " - 7.2.99"
160-
reason: "max_docs introduced in 7.3.0"
161-
162-
- do:
163-
index:
164-
index: test
165-
id: 1
166-
body: { "text": "test" }
167-
- do:
168-
catch: /\[max_docs\] set to two different values \[4\] and \[5\]/
169-
reindex:
170-
body:
171-
source:
172-
index: test
173-
dest:
174-
index: dest
175-
size: 4
176-
max_docs: 5
177-
178161
---
179162
"inconsistent max_docs in body and max_docs in URL fails":
180163
- skip:

modules/reindex/src/test/resources/rest-api-spec/test/reindex/30_search.yml

-46
Original file line numberDiff line numberDiff line change
@@ -31,52 +31,6 @@
3131
index: target
3232
- match: { hits.total: 1 }
3333

34-
---
35-
"Sorting and size combined":
36-
- skip:
37-
version: " - 7.2.99"
38-
reason: "deprecation warnings only emitted on 7.3+"
39-
features: warnings
40-
41-
- do:
42-
index:
43-
index: test
44-
id: 1
45-
body: { "order": 1 }
46-
- do:
47-
index:
48-
index: test
49-
id: 2
50-
body: { "order": 2 }
51-
- do:
52-
indices.refresh: {}
53-
54-
- do:
55-
warnings:
56-
- Deprecated field [size] used, expected [max_docs] instead
57-
reindex:
58-
refresh: true
59-
body:
60-
size: 1
61-
source:
62-
index: test
63-
sort: order
64-
dest:
65-
index: target
66-
67-
- do:
68-
search:
69-
rest_total_hits_as_int: true
70-
index: target
71-
- match: { hits.total: 1 }
72-
73-
- do:
74-
search:
75-
rest_total_hits_as_int: true
76-
index: target
77-
q: order:1
78-
- match: { hits.total: 1 }
79-
8034
---
8135
"Sorting and size combined pre 7.3":
8236
- skip:

0 commit comments

Comments
 (0)