Skip to content

Commit 34cbed6

Browse files
Added javadoc
1 parent 3346b40 commit 34cbed6

File tree

4 files changed

+68
-9
lines changed

4 files changed

+68
-9
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ public final void bulkAsync(BulkRequest bulkRequest, RequestOptions options, Act
374374
}
375375

376376
/**
377-
* Executes a bulk request using the Bulk API.
377+
* Executes a reindex request.
378378
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html">Reindex API on elastic.co</a>
379379
* @param reindexRequest the request
380380
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
@@ -388,7 +388,7 @@ public final BulkByScrollResponse reindex(ReindexRequest reindexRequest, Request
388388
}
389389

390390
/**
391-
* Asynchronously executes a bulk request using the Bulk API.
391+
* Asynchronously executes a reindex request.
392392
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html">Reindex API on elastic.co</a>
393393
* @param reindexRequest the request
394394
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,25 @@
2121

2222
import org.elasticsearch.common.unit.TimeValue;
2323
import org.elasticsearch.action.bulk.BulkItemResponse.Failure;
24+
import org.elasticsearch.common.xcontent.ObjectParser;
2425
import org.elasticsearch.index.reindex.ScrollableHitSource.SearchFailure;
2526
import org.elasticsearch.index.reindex.BulkByScrollTask.StatusBuilder;
2627

2728
import java.util.ArrayList;
2829
import java.util.List;
2930
import java.util.concurrent.TimeUnit;
3031

31-
public class BulkByScrollResponseBuilder extends StatusBuilder {
32+
/**
33+
* Helps build a {@link BulkByScrollResponse}. Used by an instance of {@link ObjectParser} when parsing from XContent.
34+
*/
35+
class BulkByScrollResponseBuilder extends StatusBuilder {
3236
private TimeValue took;
3337
private BulkByScrollTask.Status status;
3438
private List<Failure> bulkFailures = new ArrayList<>();
3539
private List<SearchFailure> searchFailures = new ArrayList<>();
3640
private boolean timedOut;
3741

38-
public BulkByScrollResponseBuilder() {}
42+
BulkByScrollResponseBuilder() {}
3943

4044
public void setTook(long took) {
4145
setTook(new TimeValue(took, TimeUnit.MILLISECONDS));

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ public boolean shouldCancelChildrenOnCancellation() {
202202
return true;
203203
}
204204

205+
/**
206+
* This class acts as a builder for {@link Status}. Once the {@link Status} object is built by calling
207+
* {@link #buildStatus()} it is immutable. Used by an instance of {@link ObjectParser} when parsing from
208+
* XContent.
209+
*/
205210
public static class StatusBuilder {
206211
private Integer sliceId = null;
207212
private Long total = null;
@@ -558,6 +563,11 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
558563
return builder.endObject();
559564
}
560565

566+
/**
567+
* We need to write a manual parser for this because of {@link StatusOrException}. Since
568+
* {@link StatusOrException#fromXContent(XContentParser)} tries to peek at a field first before deciding
569+
* what needs to be it cannot use an {@link ObjectParser}.
570+
*/
561571
public XContentBuilder innerXContent(XContentBuilder builder, Params params)
562572
throws IOException {
563573
if (sliceId != null) {
@@ -961,6 +971,13 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
961971
return builder;
962972
}
963973

974+
/**
975+
* Since {@link StatusOrException} can contain either an {@link Exception} or a {@link Status} we need to peek
976+
* at a field first before deciding what needs to be parsed since the same object could contains either.
977+
* The {@link #EXPECTED_EXCEPTION_FIELDS} contains the fields that are expected when the serialised object
978+
* was an instance of exception and the {@link Status#FIELDS_SET} is the set of fields expected when the
979+
* serialized object was an instance of Status.
980+
*/
964981
public static StatusOrException fromXContent(XContentParser parser) throws IOException {
965982
XContentParser.Token token = parser.currentToken();
966983
if (token == null) {

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

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
* to which documents are written.
4646
*/
4747
public class ReindexRequest extends AbstractBulkIndexByScrollRequest<ReindexRequest>
48-
implements CompositeIndicesRequest, ToXContentObject {
48+
implements CompositeIndicesRequest, ToXContentObject {
4949
/**
5050
* Prototype for index requests.
5151
*/
@@ -128,25 +128,37 @@ private boolean routingIsValid() {
128128
}
129129
}
130130

131+
/**
132+
* Set the indices which will act as the source for the ReindexRequest
133+
*/
131134
public ReindexRequest setSourceIndices(String... sourceIndices) {
132135
if (sourceIndices != null) {
133136
this.getSearchRequest().indices(sourceIndices);
134137
}
135138
return this;
136139
}
137140

141+
/**
142+
* Set the document types which need to be copied from the source indices
143+
*/
138144
public ReindexRequest setSourceDocTypes(String... docTypes) {
139145
if (docTypes != null) {
140146
this.getSearchRequest().types(docTypes);
141147
}
142148
return this;
143149
}
144150

151+
/**
152+
* Sets the scroll size for setting how many documents are to be processed in one batch during reindex
153+
*/
145154
public ReindexRequest setSourceBatchSize(int size) {
146155
this.getSearchRequest().source().size(size);
147156
return this;
148157
}
149158

159+
/**
160+
* Set the query for selecting documents from the source indices
161+
*/
150162
public ReindexRequest setSourceQuery(QueryBuilder queryBuilder) {
151163
if (queryBuilder != null) {
152164
this.getSearchRequest().source().query(queryBuilder);
@@ -158,34 +170,51 @@ public ReindexRequest setSourceQuery(QueryBuilder queryBuilder) {
158170
* Add a sort against the given field name.
159171
*
160172
* @param name The name of the field to sort by
173+
* @param order The order in which to sort
161174
*/
162175
public ReindexRequest addSortField(String name, SortOrder order) {
163176
this.getSearchRequest().source().sort(name, order);
164177
return this;
165178
}
166179

180+
/**
181+
* Set the target index for the ReindexRequest
182+
*/
167183
public ReindexRequest setDestIndex(String destIndex) {
168184
if (destIndex != null) {
169185
this.getDestination().index(destIndex);
170186
}
171187
return this;
172188
}
173189

190+
/**
191+
* Set the document type for the destination index
192+
*/
174193
public ReindexRequest setDestDocType(String docType) {
175194
this.getDestination().type(docType);
176195
return this;
177196
}
178197

198+
/**
199+
* Set the routing to decide which shard the documents need to be routed to
200+
*/
179201
public ReindexRequest setDestRouting(String routing) {
180202
this.getDestination().routing(routing);
181203
return this;
182204
}
183205

206+
/**
207+
* Set the version type for the target index. A {@link VersionType#EXTERNAL} helps preserve the version
208+
* if the document already existed in the target index.
209+
*/
184210
public ReindexRequest setDestVersionType(VersionType versionType) {
185211
this.getDestination().versionType(versionType);
186212
return this;
187213
}
188214

215+
/**
216+
* Allows to set the ingest pipeline for the target index.
217+
*/
189218
public void setDestPipeline(String pipelineName) {
190219
this.getDestination().setPipeline(pipelineName);
191220
}
@@ -199,15 +228,24 @@ public ReindexRequest setDestOpType(String opType) {
199228
return this;
200229
}
201230

202-
public IndexRequest getDestination() {
203-
return destination;
204-
}
205-
231+
/**
232+
* Set the {@link RemoteInfo} if the source indices are in a remote cluster.
233+
*/
206234
public ReindexRequest setRemoteInfo(RemoteInfo remoteInfo) {
207235
this.remoteInfo = remoteInfo;
208236
return this;
209237
}
210238

239+
/**
240+
* Gets the target for this reindex request in the for of an {@link IndexRequest}
241+
*/
242+
public IndexRequest getDestination() {
243+
return destination;
244+
}
245+
246+
/**
247+
* Get the {@link RemoteInfo} if it was set for this request.
248+
*/
211249
public RemoteInfo getRemoteInfo() {
212250
return remoteInfo;
213251
}

0 commit comments

Comments
 (0)