Skip to content

Commit

Permalink
removed redundant setter and fixed docs
Browse files Browse the repository at this point in the history
  • Loading branch information
sohaibiftikhar committed Aug 28, 2018
1 parent 906aff7 commit 71039ac
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ public void testUpdateByQuery() throws IOException {
{
// test1: create one doc in dest
UpdateByQueryRequest updateByQueryRequest = new UpdateByQueryRequest();
updateByQueryRequest.setIndices(sourceIndex);
updateByQueryRequest.indices(sourceIndex);
updateByQueryRequest.setQuery(new IdsQueryBuilder().addIds("1").types("type"));
updateByQueryRequest.setRefresh(true);
BulkByScrollResponse bulkResponse =
Expand All @@ -735,7 +735,7 @@ public void testUpdateByQuery() throws IOException {
{
// test2: update using script
UpdateByQueryRequest updateByQueryRequest = new UpdateByQueryRequest();
updateByQueryRequest.setIndices(sourceIndex);
updateByQueryRequest.indices(sourceIndex);
updateByQueryRequest.setScript(new Script("if (ctx._source.foo == 2) ctx._source.foo++;"));
updateByQueryRequest.setRefresh(true);
BulkByScrollResponse bulkResponse =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ public void testReindex() throws IOException {

public void testUpdateByQuery() throws IOException {
UpdateByQueryRequest updateByQueryRequest = new UpdateByQueryRequest();
updateByQueryRequest.setIndices(randomIndicesNames(1, 5));
updateByQueryRequest.indices(randomIndicesNames(1, 5));
Map<String, String> expectedParams = new HashMap<>();
if (randomBoolean()) {
updateByQueryRequest.setDocTypes(generateRandomStringArray(5, 5, false, false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -924,8 +924,7 @@ public void testUpdateByQuery() throws Exception {
}
{
// tag::update-by-query-request
UpdateByQueryRequest request = new UpdateByQueryRequest(); // <1>
request.setIndices("source1", "source2"); // <2>
UpdateByQueryRequest request = new UpdateByQueryRequest("source1", "source2"); // <1>
// end::update-by-query-request
// tag::update-by-query-request-conflicts
request.setConflicts("proceed"); // <1>
Expand Down Expand Up @@ -993,7 +992,7 @@ public void testUpdateByQuery() throws Exception {
}
{
UpdateByQueryRequest request = new UpdateByQueryRequest();
request.setIndices("source1");
request.indices("source1");

// tag::update-by-query-execute-listener
ActionListener<BulkByScrollResponse> listener = new ActionListener<BulkByScrollResponse>() {
Expand Down
5 changes: 2 additions & 3 deletions docs/java-rest/high-level/document/update-by-query.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@

A `UpdateByQueryRequest` can be used to update documents in an index.

It requires an existing index and a target index which may or may not exist pre-request.
It requires an existing index (or a set of indices) on which the update is to be performed.

The simplest form of a `UpdateByQueryRequest` looks like follows:

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests}/CRUDDocumentationIT.java[update-by-query-request]
--------------------------------------------------
<1> Creates the `UpdateByQueryRequest`
<2> Adds a list of sources to update
<1> Creates the `UpdateByQueryRequest` on a set of indices.

By default version conflicts abort the `UpdateByQueryRequest` process but you can just count them by settings it to
`proceed` in the request body
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public UpdateByQueryRequest() {
this(new SearchRequest());
}

public UpdateByQueryRequest(String... indices) {
this(new SearchRequest(indices));
}

UpdateByQueryRequest(SearchRequest search) {
this(search, true);
}
Expand Down Expand Up @@ -89,16 +93,6 @@ public UpdateByQueryRequest setDocTypes(String... types) {
return this;
}

/**
* Set the indices on which the update by query request is to be run
*/
public UpdateByQueryRequest setIndices(String... indices) {
if (indices != null) {
getSearchRequest().indices(indices);
}
return this;
}

/**
* Set routing limiting the process to the shards that match that routing value
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void testUpdateByQueryRequestImplementsIndicesRequestReplaceable() {
IndicesOptions indicesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean());

UpdateByQueryRequest request = new UpdateByQueryRequest();
request.setIndices(indices);
request.indices(indices);
request.setIndicesOptions(indicesOptions);
for (int i = 0; i < numIndices; i++) {
assertEquals(indices[i], request.indices()[i]);
Expand All @@ -59,7 +59,7 @@ public void testUpdateByQueryRequestImplementsIndicesRequestReplaceable() {

@Override
protected UpdateByQueryRequest newRequest() {
return new UpdateByQueryRequest().setIndices(randomAlphaOfLength(5));
return new UpdateByQueryRequest(randomAlphaOfLength(5));
}

@Override
Expand Down

0 comments on commit 71039ac

Please sign in to comment.