opensearch-project / opensearch-project/opensearch-java

[FEATURE] `BoolQuery`: provide methods with varargs query builders

Open
#1,548 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.