Java api client to implement a complex query

The terms query can be configured in two ways: using a list of term values, or using a terms lookup configuration.

In your case, I guess you want to use a list of term values.

Assuming you have a variable List<String> terms:

List<String> terms = Collections.singletonList("");
List<FieldValue> termValues = terms.stream().map(FieldValue::of).collect(Collectors.toList());
        
...
    .bool(b -> b
        .must(m -> m
            .terms(t -> t
                .field("")
                    .terms(tf -> tf
                        .value(termValues)
                    )
                )
            )
...

Hope this helps.