Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Indices Aliases API to the high level REST client #27876

Merged
merged 4 commits into from
Jan 25, 2018

Conversation

olcbean
Copy link
Contributor

@olcbean olcbean commented Dec 18, 2017

Add Indices Aliases API to the high level REST client

Relates to #27205

@elasticmachine
Copy link
Collaborator

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

@cbuescher
Copy link
Member

@elasticmachine test this please

@elasticmachine
Copy link
Collaborator

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

@cbuescher
Copy link
Member

@olcbean thanks for taking this on, I hope I will be able to look at it shortly. In the meanwhile, could you rebase your branch, unfortunately the "core" project was renamed to "server" in the meantime so the changes in core while have conflicts. Hopefully a simple rebase is enough.

@olcbean
Copy link
Contributor Author

olcbean commented Jan 16, 2018

@cbuescher thanks for picking this one up! I just rebased

@cbuescher
Copy link
Member

@elasticmachine test this please

@javanna javanna self-requested a review January 19, 2018 15:08
@javanna javanna assigned javanna and unassigned cbuescher Jan 19, 2018
@javanna javanna removed the request for review from cbuescher January 19, 2018 15:08
Copy link
Member

@javanna javanna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks a lot @olcbean this looks good already, I left some comments but nothing major, once those are addressed I will merge.

* "https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html">
* Index Aliases API on elastic.co</a>
*/
public IndicesAliasesResponse aliases(IndicesAliasesRequest indicesAliasesRequest, Header... headers) throws IOException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In our SPEC we call this update_aliases. Can you rename these new methods to updateAliases please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest I struggled with the naming here..
AFAICS the rest specs are referring to it as update_aliases, the IndicesAdminClient uses aliases, ( as the end point itself is aliases ), and the corresponding request and response are respectively IndicesAliasesRequest and IndicesAliasesResponse. So I was somewhat reluctant to bring a new updateAliases into the mix.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea I hear you. This comes from the fact that Java was always a special client. I think it makes sense to follow the SPEC convention at this point. Although the request and response follow a different one. We can always rename them later.

@@ -164,6 +165,15 @@ static Request createIndex(CreateIndexRequest createIndexRequest) throws IOExcep
HttpEntity entity = createEntity(createIndexRequest, REQUEST_BODY_CONTENT_TYPE);
return new Request(HttpPut.METHOD_NAME, endpoint, parameters.getParams(), entity);
}

static Request indicesAliases(IndicesAliasesRequest indicesAliasesRequest) throws IOException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same rename as above?

@@ -135,6 +141,97 @@ public void testDeleteIndex() throws IOException {
}
}

@SuppressWarnings("unchecked")
public void testAliases() throws IOException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testUpdateAliases?

@@ -270,6 +273,24 @@ public void testCreateIndex() throws IOException {
assertToXContentBody(createIndexRequest, request.getEntity());
}

public void testIndicesAliases() throws IOException {
IndicesAliasesRequest indicesAliasesRequest = new IndicesAliasesRequest();
int numberOfAliasesRequests = 1;//randomIntBetween(0, 5);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what did you mean to do with the randomization? I wonder if it gets too complicated with multiple randomized actions...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check that 0 and multiple it is still OK. Should I go back to a single action only?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe, I mean in this unit test randomizing the request body so heavily may not make a huge difference. I don't have a strong opinion though, what do you think?

@@ -0,0 +1,89 @@
[[java-rest-high-indices-aliases]]
=== Index Aliases API
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too, let's call it update aliases like in the SPEC?

builder.field(INDICES.getPreferredName(), indices);
}
if (0 != aliases.length) {
builder.field(ALIASES.getPreferredName(), aliases);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be builder.array ?

@@ -311,6 +325,19 @@ public void testRoundTrip() throws IOException {
}
}

public void testFromToXContent() throws IOException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks a lot for adding this, I know the effort it took code-wise :)

import static org.elasticsearch.test.ESTestCase.randomIntBetween;
import static org.elasticsearch.test.ESTestCase.randomLong;

public class RandomAliasActionsGenerator {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about folding this into AliasActionsTests and remove randomization from RequestTests? just an idea, let me know what you think.

}
assertThat(parsedAction, equalTo(action));
}
}

private Map<String, Object> randomMap(int maxDepth) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see some duplication her between the newly added generator and this method. Maybe we can address that too?


It is possible to associate routing values with aliases. This feature can be
used together with filtering aliases in order to avoid unnecessary shard
operations.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should explain here the feature/API itself or rather just mention how to use it and point to the API docs to know more about it. What do you think about rephrasing to just say e.g. "use this to set a routing value" etc. without explaining what routing is in this page?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean to follow the low level client docs approach? Just say how to use requests / responses with a few examples.
Or do you mean to have a simple example for every supported API with a request / response and a link to the API docs?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

besides the link, I wouldn't explain here what the API does and how the different options work. Just how to use the options with the client. At least I think this is what we've done until now. Makes sense?

@olcbean
Copy link
Contributor Author

olcbean commented Jan 24, 2018

@javanna I just pushed a commit to address your comments. Can you have a look?

( I did not rename the asciidoc to updateAliases and did not rebase in order to minimize the noise for the review. I will do that in the last commit )

Copy link
Member

@javanna javanna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left two tiny comments, LGTM otherwise.

Defining an alias with filters provide an easy way to create different
"views" of the same index. The filter can be defined using Query DSL and is
applied to all Search, Count, Delete By Query and More Like This operations
with this alias.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here can we just describe how to add a filter rather than describing what filters do and where they get applied?

<3> Add the alias action to the request

The following action types are supported: `add` - alias an index, `remove` -
remove the alias assosiated with the index and `remove_index` - deletes the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/assosiated/associated

@olcbean
Copy link
Contributor Author

olcbean commented Jan 24, 2018

@javanna have another look?

@javanna
Copy link
Member

javanna commented Jan 24, 2018

looks good @olcbean , just needs rebasing/merging master in

@olcbean
Copy link
Contributor Author

olcbean commented Jan 25, 2018

@javanna I just rebased and changed the docs as well ;)

@javanna
Copy link
Member

javanna commented Jan 25, 2018

test this please

@javanna javanna merged commit 9db23e4 into elastic:master Jan 25, 2018
@javanna
Copy link
Member

javanna commented Jan 25, 2018

thanks @olcbean !

javanna pushed a commit that referenced this pull request Jan 25, 2018
jasontedor added a commit to matarrese/elasticsearch that referenced this pull request Jan 25, 2018
* master: (23 commits)
  Update Netty to 4.1.16.Final (elastic#28345)
  Fix peer recovery flushing loop (elastic#28350)
  REST high-level client: add support for exists alias (elastic#28332)
  REST high-level client: move to POST when calling API to retrieve which support request body (elastic#28342)
  Add Indices Aliases API to the high level REST client (elastic#27876)
  Java Api clean up: remove deprecated `isShardsAcked` (elastic#28311)
  [Docs] Fix explanation for `from` and `size` example (elastic#28320)
  Adapt bwc version after backport elastic#28358
  Always return the after_key in composite aggregation response (elastic#28358)
  Adds test name to MockPageCacheRecycler exception (elastic#28359)
  Adds a note in the `terms` aggregation docs regarding pagination (elastic#28360)
  [Test] Fix DiscoveryNodesTests.testDeltas() (elastic#28361)
  Update packaging tests to work with meta plugins (elastic#28336)
  Remove Painless Type from MethodWriter in favor of Java Class. (elastic#28346)
  [Doc] Fixs typo in reverse-nested-aggregation.asciidoc (elastic#28348)
  Reindex: Shore up rethrottle test
  Only assert single commit iff index created on 6.2
  isHeldByCurrentThread should return primitive bool
  [Docs] Clarify `html` encoder in highlighting.asciidoc (elastic#27766)
  Fix GeoDistance query example (elastic#28355)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants