opensearch-project / opensearch-project/opensearch-java
[FEATURE] `BoolQuery`: provide methods with varargs query builders
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 165
- Forks
- 250
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 26
Description
Is your feature request related to a problem?
n/a
What solution would you like?
the following APIs currently exist to add more than one entry (shown with filter, but the same is true for must & co.):
https://github.com/opensearch-project/opensearch-java/blob/fa5add510ebcb0c1b4b7291d57f453a381434015/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/BoolQuery.java#L308
https://github.com/opensearch-project/opensearch-java/blob/fa5add510ebcb0c1b4b7291d57f453a381434015/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/BoolQuery.java#L324
however, when you wish to use a builder pattern for the query you can only specify a single builder:
https://github.com/opensearch-project/opensearch-java/blob/fa5add510ebcb0c1b4b7291d57f453a381434015/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/BoolQuery.java#L340
it'd be great if there could be a corresponding varargs method:
public final Builder filter(Function<Query.Builder, ObjectBuilder<Query>> fn, Function<Query.Builder, ObjectBuilder<Query>>... fns)
this would then allow writing more concise code:
new Query.Builder().bool(b -> b.must(q -> q.match(...), q -> q.match(...)));
What alternatives have you considered?
it's of course possible to use the builder manually, but this is more cumbersome:
new Query.Builder().bool(b -> b.must(new Query.Builder().match(...).build(), new Query.Builder().match(...).build()));
Do you have any additional context?
this most likely also affects other classes, i just found it on BoolQuery.
since this class is generated i presume that it's possible to solve this at some central point and then re-generate all classes, leading to more convenient APIs everywhere.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the generated java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/BoolQuery.java, especially the existing filter, must, and builder overloads linked in the issue. Trace how this generated class is produced to find the central change point rather than editing only BoolQuery.java. Done means builder-based varargs methods are available for BoolQuery and any other affected generated query APIs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100