# Java Api Client TermsQueryBuilder how to add terms from collection of strings

**URL:** <https://discuss.elastic.co/t/java-api-client-termsquerybuilder-how-to-add-terms-from-collection-of-strings/293464>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [January 4, 2022, 4:01pm UTC](https://discuss.elastic.co/t/java-api-client-termsquerybuilder-how-to-add-terms-from-collection-of-strings/293464 "2022-01-04T16:01:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Piotr\_Idzikowski](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/piotr_idzikowski/32/99812_2.png) [@Piotr\_Idzikowski](https://discuss.elastic.co/u/Piotr_Idzikowski)\
**Post date:** [January 4, 2022, 4:01pm UTC](https://discuss.elastic.co/t/java-api-client-termsquerybuilder-how-to-add-terms-from-collection-of-strings/293464/1 "2022-01-04T16:01:21Z")

</div>

Hello.  
The only available method is by ObjectBuilder value(List v) method.  
Why there is no option to add just a list of Strings?

I am using Elasticsearch-java-7.16.2 version

---

<div class="post-metadata">

**Author:** ![Piotr\_Idzikowski](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/piotr_idzikowski/32/99812_2.png) [@Piotr\_Idzikowski](https://discuss.elastic.co/u/Piotr_Idzikowski)\
**Post date:** [January 4, 2022, 4:06pm UTC](https://discuss.elastic.co/t/java-api-client-termsquerybuilder-how-to-add-terms-from-collection-of-strings/293464/2 "2022-01-04T16:06:44Z")

</div>

I had to finish with something like that:  
.terms(tqf -\> tqf.value(fClasses.stream().map(FieldValue::of).collect(Collectors.toList())))))  
which in my opinion doesn't look pretty.  
There should be a better way, isn't it?

---

<div class="post-metadata">

**Author:** ![swallez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/swallez/32/11972_2.png) [@swallez](https://discuss.elastic.co/u/swallez)\
**Post date:** [January 5, 2022, 10:21am UTC](https://discuss.elastic.co/t/java-api-client-termsquerybuilder-how-to-add-terms-from-collection-of-strings/293464/3 "2022-01-05T10:21:14Z")

</div>

The `FieldValue` class represents the various value types of index fields. This is indeed unnecessarily complex.

A way to simplify things would be to add an additional method to FieldValue:  
`static List<FieldValue> of(List<String> list)`  
which would then allow writing:

`.terms (tqf -> tqf.value(FieldValue.of(fClasses)))`

Would that help? And of course similar methods would be added for collection/arrays of other types supported by FieldValue

---

<div class="post-metadata">

**Author:** ![Piotr\_Idzikowski](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/piotr_idzikowski/32/99812_2.png) [@Piotr\_Idzikowski](https://discuss.elastic.co/u/Piotr_Idzikowski)\
**Post date:** [January 5, 2022, 1:17pm UTC](https://discuss.elastic.co/t/java-api-client-termsquerybuilder-how-to-add-terms-from-collection-of-strings/293464/4 "2022-01-05T13:17:13Z")

</div>

Yes, that would be useful, but what about adding an additional method to TermsQueryField$Builder:

```auto
public ObjectBuilder<TermsQueryField> value(List<String> v)

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 2, 2022, 1:18pm UTC](https://discuss.elastic.co/t/java-api-client-termsquerybuilder-how-to-add-terms-from-collection-of-strings/293464/5 "2022-02-02T13:18:07Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
