-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Implement update by query #1644
Implement update by query #1644
Conversation
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.
#1446 is about adding the update by query feature to the library. This means that both ReactiveDocumentOperations
and DocumentOperations
and their implementations (both on-reactive and reactive) must have either their update methods enhanced to support this case.
Your PR only adds code to the reactive client and not the the operations/templates.
Hi @sothawo, for |
Yes, we do not want to leak Elasticsearch types into the Spring Data Elasticsearch API. Although there are a few places where this happens, returning Aggregations for example. These places are either old code that has not been fixed or where we did not have the resources yet to change that. For new additions we should not do this. About how a solution could be done, check my comment in the issue and let me know what you think about it. |
1a65f9f
to
30ad335
Compare
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 looks pretty good, thanks a lot for your work. I made some remarks.
Can you please rebase your branch onto master and force push it? I had a PR merged that deals with custom routing and I want to see how this fits together with the routing for the updates
src/main/java/org/springframework/data/elasticsearch/core/query/BulkByScrollResponse.java
Outdated
Show resolved
Hide resolved
src/main/java/org/springframework/data/elasticsearch/core/query/BulkByScrollResponse.java
Outdated
Show resolved
Hide resolved
src/main/java/org/springframework/data/elasticsearch/core/query/BulkByScrollResponse.java
Outdated
Show resolved
Hide resolved
src/main/java/org/springframework/data/elasticsearch/core/query/BulkByScrollResponse.java
Outdated
Show resolved
Hide resolved
src/main/java/org/springframework/data/elasticsearch/core/ScriptType.java
Outdated
Show resolved
Hide resolved
src/main/java/org/springframework/data/elasticsearch/core/ScriptType.java
Show resolved
Hide resolved
src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchRestTemplateTests.java
Outdated
Show resolved
Hide resolved
return updateByQueryRequest; | ||
} | ||
|
||
public UpdateByQueryRequestBuilder updateByQueryRequestBuilderFor(Client client, UpdateQuery query, IndexCoordinates index) { |
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.
public UpdateByQueryRequestBuilder updateByQueryRequestBuilderFor(Client client, UpdateQuery query, IndexCoordinates index) { | |
public UpdateByQueryRequestBuilder updateByQueryRequestBuilder(Client client, UpdateQuery query, IndexCoordinates index) { |
please remove these For suffixes. Don't know why I named this function that 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.
done
return new BulkByScrollResponseBuilder(); | ||
} | ||
|
||
public static BulkByScrollResponse translateFrom(org.elasticsearch.index.reindex.BulkByScrollResponse bulkByScrollResponse) { |
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.
public static BulkByScrollResponse translateFrom(org.elasticsearch.index.reindex.BulkByScrollResponse bulkByScrollResponse) { | |
public static BulkByScrollResponse from(org.elasticsearch.index.reindex.BulkByScrollResponse bulkByScrollResponse) { |
We name such factory methods normally just from(...)
or of(...)
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.
done for of(...)
Params params = new Params(request) | ||
.withRouting(updateByQueryRequest.getRouting()) | ||
.withPipeline(updateByQueryRequest.getPipeline()) | ||
.withRefresh(updateByQueryRequest.isRefresh()) | ||
.withTimeout(updateByQueryRequest.getTimeout()) | ||
.withWaitForActiveShards(updateByQueryRequest.getWaitForActiveShards()) | ||
.withRequestsPerSecond(updateByQueryRequest.getRequestsPerSecond()) |
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.
If you want to have this formatting, you need to add //
to the end of every line. Otherwise the formatter settings will set it back to the longer lines.
I would prefer to change the formatter, but that's the Spring Data style.
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.
done
30ad335
to
d04bdc1
Compare
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.
two potential places with wrong code, otherwise minor stuff
@@ -1404,7 +1398,7 @@ public UpdateRequest updateRequest(UpdateQuery query, IndexCoordinates index) { | |||
if (params == null) { | |||
params = new HashMap<>(); | |||
} | |||
Script script = new Script(ScriptType.INLINE, query.getLang(), query.getScript(), params); | |||
Script script = new Script(getScriptType(ScriptType.INLINE), query.getLang(), query.getScript(), params); |
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.
shouldn't that be
Script script = new Script(getScriptType(ScriptType.INLINE), query.getLang(), query.getScript(), params); | |
Script script = new Script(getScriptType(query.getScriptType()), query.getLang(), query.getScript(), params); |
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.
done
@@ -1478,7 +1472,7 @@ public UpdateRequestBuilder updateRequestBuilderFor(Client client, UpdateQuery q | |||
if (params == null) { | |||
params = new HashMap<>(); | |||
} | |||
Script script = new Script(ScriptType.INLINE, query.getLang(), query.getScript(), params); | |||
Script script = new Script(getScriptType(ScriptType.INLINE), query.getLang(), query.getScript(), params); |
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.
Script script = new Script(getScriptType(ScriptType.INLINE), query.getLang(), query.getScript(), params); | |
Script script = new Script(getScriptType(query.getScriptType(), query.getLang(), query.getScript(), params); |
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.
done
|
||
private UpdateByQueryResponse(long took, boolean timedOut, long total, long updated, long deleted, int batches, | ||
long versionConflicts, long noops, long bulkRetries, long searchRetries, | ||
String reasonCancelled, List<Failure> failures) { |
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.
String reasonCancelled, List<Failure> failures) { | |
@Nullable String reasonCancelled, List<Failure> failures) { |
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.
done
* @param failure {@link BulkItemResponse.Failure} to translate | ||
* @return a new {@link Failure} | ||
*/ | ||
public static Failure translateFrom(BulkItemResponse.Failure failure) { |
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.
public static Failure translateFrom(BulkItemResponse.Failure failure) { | |
public static Failure of(BulkItemResponse.Failure failure) { |
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.
done
d04bdc1
to
75f5a70
Compare
75f5a70
to
9904ddd
Compare
Closes #1446