Skip to content

Commit 1d745f1

Browse files
Revert "Deprecate sorting in reindex (elastic#49458)"
This reverts commit 27d45c9.
1 parent 7cf1708 commit 1d745f1

File tree

8 files changed

+48
-95
lines changed

8 files changed

+48
-95
lines changed

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

+5
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
import org.elasticsearch.script.Script;
8484
import org.elasticsearch.script.ScriptType;
8585
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
86+
import org.elasticsearch.search.sort.SortOrder;
8687
import org.elasticsearch.tasks.TaskId;
8788

8889
import java.util.Collections;
@@ -832,6 +833,10 @@ public void testReindex() throws Exception {
832833
// tag::reindex-request-pipeline
833834
request.setDestPipeline("my_pipeline"); // <1>
834835
// end::reindex-request-pipeline
836+
// tag::reindex-request-sort
837+
request.addSortField("field1", SortOrder.DESC); // <1>
838+
request.addSortField("field2", SortOrder.ASC); // <2>
839+
// end::reindex-request-sort
835840
// tag::reindex-request-script
836841
request.setScript(
837842
new Script(

docs/java-rest/high-level/document/reindex.asciidoc

+10
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ include-tagged::{doc-tests-file}[{api}-request-pipeline]
8989
--------------------------------------------------
9090
<1> set pipeline to `my_pipeline`
9191

92+
If you want a particular set of documents from the source index you’ll need to use sort. If possible, prefer a more
93+
selective query to maxDocs and sort.
94+
95+
["source","java",subs="attributes,callouts,macros"]
96+
--------------------------------------------------
97+
include-tagged::{doc-tests-file}[{api}-request-sort]
98+
--------------------------------------------------
99+
<1> add descending sort to`field1`
100+
<2> add ascending sort to `field2`
101+
92102
+{request}+ also supports a `script` that modifies the document. It allows you to
93103
also change the document's metadata. The following example illustrates that.
94104

docs/reference/docs/reindex.asciidoc

+30-12
Original file line numberDiff line numberDiff line change
@@ -476,14 +476,9 @@ which defaults to a maximum size of 100 MB.
476476
(Optional, integer) Total number of slices.
477477

478478
`sort`:::
479-
+
480-
--
481479
(Optional, list) A comma-separated list of `<field>:<direction>` pairs to sort by before indexing.
482480
Use in conjunction with `max_docs` to control what documents are reindexed.
483481

484-
deprecated::[7.6, Sort in reindex is deprecated. Sorting in reindex was never guaranteed to index documents in order and prevents further development of reindex such as resilience and performance improvements. If used in combination with `max_docs`&#44; consider using a query filter instead.]
485-
--
486-
487482
`_source`:::
488483
(Optional, string) If `true` reindexes all source fields.
489484
Set to a list to reindex select fields.
@@ -607,8 +602,8 @@ POST _reindex
607602
--------------------------------------------------
608603
// TEST[setup:twitter]
609604

610-
[[docs-reindex-select-max-docs]]
611-
===== Reindex select documents with `max_docs`
605+
[[docs-reindex-select-sort]]
606+
===== Reindex select documents with sort
612607

613608
You can limit the number of processed documents by setting `max_docs`.
614609
For example, this request copies a single document from `twitter` to
@@ -629,6 +624,28 @@ POST _reindex
629624
--------------------------------------------------
630625
// TEST[setup:twitter]
631626

627+
You can use `sort` in conjunction with `max_docs` to select the documents you want to reindex.
628+
Sorting makes the scroll less efficient but in some contexts it's worth it.
629+
If possible, it's better to use a more selective query instead of `max_docs` and `sort`.
630+
631+
For example, following request copies 10000 documents from `twitter` into `new_twitter`:
632+
633+
[source,console]
634+
--------------------------------------------------
635+
POST _reindex
636+
{
637+
"max_docs": 10000,
638+
"source": {
639+
"index": "twitter",
640+
"sort": { "date": "desc" }
641+
},
642+
"dest": {
643+
"index": "new_twitter"
644+
}
645+
}
646+
--------------------------------------------------
647+
// TEST[setup:twitter]
648+
632649
[[docs-reindex-multiple-indices]]
633650
===== Reindex from multiple indices
634651

@@ -808,10 +825,11 @@ POST _reindex
808825
"index": "twitter",
809826
"query": {
810827
"function_score" : {
811-
"random_score" : {},
812-
"min_score" : 0.9 <1>
828+
"query" : { "match_all": {} },
829+
"random_score" : {}
813830
}
814-
}
831+
},
832+
"sort": "_score" <1>
815833
},
816834
"dest": {
817835
"index": "random_twitter"
@@ -820,8 +838,8 @@ POST _reindex
820838
----------------------------------------------------------------
821839
// TEST[setup:big_twitter]
822840

823-
<1> You may need to adjust the `min_score` depending on the relative amount of
824-
data extracted from source.
841+
<1> `_reindex` defaults to sorting by `_doc` so `random_score` will not have any
842+
effect unless you override the sort to `_score`.
825843

826844
[[reindex-scripts]]
827845
===== Modify documents during reindexing

docs/reference/ilm/ilm-with-existing-indices.asciidoc

+1-5
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,6 @@ will mean that all documents in `ilm-mylogs-000001` come before all documents in
352352
`ilm-mylogs-000002`, and so on. However, if this is not a requirement, omitting
353353
the sort will allow the data to be reindexed more quickly.
354354

355-
NOTE: Sorting in reindex is deprecated, see
356-
<<docs-reindex-api-request-body,reindex request body>>. Instead use timestamp
357-
ranges to partition data in separate reindex runs.
358-
359355
IMPORTANT: If your data uses document IDs generated by means other than
360356
Elasticsearch's automatic ID generation, you may need to do additional
361357
processing to ensure that the document IDs don't conflict during the reindex, as
@@ -408,4 +404,4 @@ PUT _cluster/settings
408404
All of the reindexed data should now be accessible via the alias set up above,
409405
in this case `mylogs`. Once you have verified that all the data has been
410406
reindexed and is available in the new indices, the existing indices can be
411-
safely removed.
407+
safely removed.

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

-9
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import org.elasticsearch.cluster.service.ClusterService;
4141
import org.elasticsearch.common.Strings;
4242
import org.elasticsearch.common.bytes.BytesReference;
43-
import org.elasticsearch.common.logging.DeprecationLogger;
4443
import org.elasticsearch.common.lucene.uid.Versions;
4544
import org.elasticsearch.common.xcontent.DeprecationHandler;
4645
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
@@ -52,7 +51,6 @@
5251
import org.elasticsearch.index.reindex.remote.RemoteScrollableHitSource;
5352
import org.elasticsearch.script.Script;
5453
import org.elasticsearch.script.ScriptService;
55-
import org.elasticsearch.search.builder.SearchSourceBuilder;
5654
import org.elasticsearch.threadpool.ThreadPool;
5755

5856
import java.io.IOException;
@@ -73,9 +71,6 @@
7371
public class Reindexer {
7472

7573
private static final Logger logger = LogManager.getLogger(Reindexer.class);
76-
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(logger);
77-
static final String SORT_DEPRECATED_MESSAGE = "The sort option in reindex is deprecated. " +
78-
"Instead consider using query filtering to find the desired subset of data.";
7974

8075
private final ClusterService clusterService;
8176
private final Client client;
@@ -93,10 +88,6 @@ public class Reindexer {
9388
}
9489

9590
public void initTask(BulkByScrollTask task, ReindexRequest request, ActionListener<Void> listener) {
96-
SearchSourceBuilder searchSource = request.getSearchRequest().source();
97-
if (searchSource != null && searchSource.sorts() != null && searchSource.sorts().isEmpty() == false) {
98-
deprecationLogger.deprecated(SORT_DEPRECATED_MESSAGE);
99-
}
10091
BulkByScrollParallelizationHelper.initTaskState(task, request, client, listener);
10192
}
10293

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

-60
This file was deleted.

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

+2-6
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,8 @@
123123
---
124124
"Sorting and max_docs in body combined":
125125
- skip:
126-
version: " - 7.5.99"
127-
reason: "max_docs introduced in 7.3.0, but sort deprecated in 7.6"
128-
features: "warnings"
126+
version: " - 7.2.99"
127+
reason: "max_docs introduced in 7.3.0"
129128

130129
- do:
131130
index:
@@ -141,9 +140,6 @@
141140
indices.refresh: {}
142141

143142
- do:
144-
warnings:
145-
- The sort option in reindex is deprecated. Instead consider using query
146-
filtering to find the desired subset of data.
147143
reindex:
148144
refresh: true
149145
body:

server/src/main/java/org/elasticsearch/index/reindex/ReindexRequest.java

-3
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,7 @@ public ReindexRequest setSourceQuery(QueryBuilder queryBuilder) {
189189
*
190190
* @param name The name of the field to sort by
191191
* @param order The order in which to sort
192-
* @deprecated Specifying a sort field for reindex is deprecated. If using this in combination with maxDocs, consider using a
193-
* query filter instead.
194192
*/
195-
@Deprecated
196193
public ReindexRequest addSortField(String name, SortOrder order) {
197194
this.getSearchRequest().source().sort(name, order);
198195
return this;

0 commit comments

Comments
 (0)