-
Notifications
You must be signed in to change notification settings - Fork 24.7k
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 Index API to High Level Rest Client #23040
Add Index API to High Level Rest Client #23040
Conversation
/** | ||
* Leave this request open until a refresh has made the contents of this request visible to search. This refresh policy is | ||
* compatible with high indexing and search throughput but it causes the request to wait to reply until a refresh occurs. | ||
*/ | ||
WAIT_UNTIL; | ||
WAIT_UNTIL((byte) 2, "wait_for"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you make this change separately please? It will need to be backported , while this PR targets master only and should only change stuff under rest-high-level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure - this part has been removed from the PR, I'll create another PR for the WriteRequest changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR created here: #23106
e227619
to
3f8dc3c
Compare
Code rebased and updated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tlrx I left a few questions and minor remarks, some of it just ideas so from my point of view this is very close.
} | ||
|
||
Params withRefreshPolicy(WriteRequest.RefreshPolicy refreshPolicy) { | ||
if (refreshPolicy != WriteRequest.RefreshPolicy.NONE) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be paranoid, but in case some other previous call to the builder set this to some other value, can we remove that value from the map in case it is set to NONE later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scratch that, I see this is private and only used internally, and the request only has one of each parameters, so duplicate calls are unlikely. Just me being paranoid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Paranoid is good sometimes :) You're right, I'll improve that in order to be remove the value in case of NONE
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall we rather have a check in putParam for the return value and assert that the value should never be there. If it is it's our bug right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
return parameters.getParams(); | ||
} | ||
|
||
private static String getEndpoint(GetRequest getRequest) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can replace calls of this helper with the new Endpoint class? Might get a tad bit longer in the end, so I'm fine either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we can. I'm also waiting for Luca opinion on those Endpoint/Params classes, but if he likes it I'll move those as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feel free to unify this with what you do with index. I like these changes overall, I left one comment on the endpoint part which may help improving things a bit, that's it.
return pathJoiner.add(getRequest.index()).add(getRequest.type()).add(getRequest.id()).toString(); | ||
} | ||
|
||
static Request index(IndexRequest indexRequest) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: maybe move this up next to the other methods (ping/exists/get) that output new Requests.
} | ||
} | ||
|
||
final XContentType xContentType = randomFrom(XContentType.values()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previous test tries all content Types, this one random choice only. Any reason for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not, it's a leftover in the previous test, XContent type must be chosen randomly at the beginning of all tests. I changed that.
|
||
Map<String, String> expectedParams = new HashMap<>(); | ||
long version = randomFrom(Versions.MATCH_DELETED, Versions.NOT_FOUND, randomNonNegativeLong()); | ||
indexRequest.version(version); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would not setting the version at all be valid here? If so, maybe also test this (e.g. rarely?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
builder.field("field_" + i, i); | ||
} | ||
builder.endObject(); | ||
indexRequest.source(builder); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if it is compatible, but maybe you can use RandomObjects#randomSource(Random random) here instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left a few comments but no blockers, LGTM
private static class Endpoint { | ||
private final List<String> parts = new ArrayList<>(); | ||
private final String delimiter = "/"; | ||
private final String prefix = "/"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given that we build a url, do we really need two constants for the same thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed to
private static final String DELIMITER = "/";
private String prefix = DELIMITER;
private String suffix = "";
and also added a withPrefix
method that was missing. I find it useful for building endpoints for Snapshot/Restore: /_snapshot
could be defined as a prefix. Just a matter of taste
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I removed all this stuff in favor of a simple concatenating method helper.
Endpoint endpoint = Endpoint.builder(); | ||
endpoint.add(indexRequest.index()); | ||
endpoint.add(indexRequest.type()); | ||
endpoint.add(indexRequest.id()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall we make it accept a varargs instead and make this a single line?
private Endpoint() { | ||
} | ||
|
||
Endpoint withSuffix(String suffix) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given that the suffix is also known before we go and provide index, type, and id... (even in case of e.g. _search) I wonder if we can get rid of the list, and just provide parts and suffix as constructor argument, then convert it into string straightaway. Not even sure we need a builder for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, let's do this.
} | ||
|
||
Params withRefreshPolicy(WriteRequest.RefreshPolicy refreshPolicy) { | ||
if (refreshPolicy != WriteRequest.RefreshPolicy.NONE) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall we rather have a check in putParam for the return value and assert that the value should never be there. If it is it's our bug right?
assertEquals(RestStatus.CONFLICT, exception.status()); | ||
assertEquals("Elasticsearch exception [type=version_conflict_engine_exception, reason=[type][with_create_op_type]: " + | ||
"version conflict, document already exists (current version [1])]", exception.getMessage()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very nice tests, thanks!
} | ||
|
||
static Request index(IndexRequest indexRequest) { | ||
String method = Strings.hasLength(indexRequest.id()) ? "PUT" : "POST"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use HttpPut.METHOD_NAME maybe? or define our own constants?
return parameters.getParams(); | ||
} | ||
|
||
private static String getEndpoint(GetRequest getRequest) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feel free to unify this with what you do with index. I like these changes overall, I left one comment on the endpoint part which may help improving things a bit, that's it.
This commit adds support for the Index API in the High Level Rest Client.
3f8dc3c
to
269e377
Compare
@cbuescher @javanna Thanks for the reviews. I updated the code according to your comments. I also had to rebase in order to use #23106 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks @cbuescher @javanna |
This commit adds support for the Index API in the High Level Rest Client.
It changes few things in the way request's parameters map is created in the high level client and changea bit RefreshPolicy in core.