-
Notifications
You must be signed in to change notification settings - Fork 191
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
[FEATURE] Add builder.copy
for external retry logic
#1228
Comments
I think I'm contributor on other opensource so I can make PR so PTAL 🙇 |
Thanks for bringing this up. It should be relatively easy to implement on the generated code. Some things to consider:
|
opensearch-java/java-client/src/main/java/org/opensearch/client/util/ObjectBuilderBase.java Lines 46 to 49 in dbd93c1
For now I simply want to pass above
index = ..;
targetId = ..;
Bool.QueryBuilder queryBuilder = builder(index, targetId, ..);
return search(queryBuilder);
--
// what I want
public doc search(queryBuilder) {
RxJava.retry(retry -> {
opensearchClient.search(queryBuilder, ..); // ⭐ on retry, re-use same query builder
});
}
--
// but now
public doc search(paramA, paramB, paramC, ..) {
newBuilder = builder.of(paramA, paramB, ..); // to build new builder, we need to pass all parameters!
RxJava.retry(retry -> {
opensearchClient.search(newBuilder, ..);
});
} To retry like above case, we need to pass all params to create builder on each retry 😢 or, I think we can easily add @Xtansia wait your opinion~! thanks! 🙇 |
@injae-kim My question is, |
public doSearch(BoolQuery.Builder queryBuilder) {
SearchRequset.Builder requestBuilder = new SearchRequest.builder().index(..).size(..)..;
RxJava.retry(() -> {
requestBuilder.query(q -> q.bool(b -> queryBuilder)); // here! re-use same queryBuilder on retry
});
} @Xtansia , aha~ I want to re-use |
@injae-kim Well the same question applies, do you need to pass around Are you varying the search request on each retry? Otherwise it should be built once outside the retry and just call |
searchAPI(params..) {
BoolQuery.Builder builder = newBuilder(params..);
search(builder);
}
search(builder) {
if (some condition) {
builder.filter(..); // add filter()
}
doSearch(builder);
}
doSearch(builder) {
if (some condition) {
builder.should(..); // add should()
}
RxJava.retry(() -> {
SearchRequest req = new Request(builder); // reuse same builder on retry
return client.search(req)
});
} @Xtansia yes. on our service, we add some more filtering on internal layer like above. I think it's common usage for other user too :) |
Is your feature request related to a problem?
opensearch-java/java-client/src/main/java/org/opensearch/client/util/ObjectBuilderBase.java
Lines 46 to 49 in dbd93c1
Users can use external retry logic with query builder like above.
But we can't re-use the same query builder on open search so
IllegalStateException
exception thrown.What solution would you like?
If we can use
queryBudiler.copy()
, it's really useful for several cases!The text was updated successfully, but these errors were encountered: