title: Creating a TermQuery with a List by using Elasticsearch Java API Client
body: <p>I am trying to convert some Java High Level REST Client code to new <a href="https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/index.html" rel="nofollow noreferrer">Elasticsearch Java API Client</a>.</p>
  <p>I want to convert this query which retrieves the contents if the id is equal to 10 or 20.</p>
  <pre><code>SearchRequest searchRequest = new SearchRequest().indices(indexName);
  
      List&lt;Long&gt; ids = new ArrayList&lt;&gt;();
      ids.add(10l);
      ids.add(20l);
  
      SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
  
      searchSourceBuilder.query(QueryBuilders.boolQuery()
          .must(QueryBuilders.termQuery(&quot;id&quot;, ids)));
  
          searchRequest.source(searchSourceBuilder);
  
  </code></pre>
  <p>With the new Java API Client I've built something like this.</p>
  <pre><code>TermsQueryField termsQueryField = new TermsQueryField.Builder()
           .value(/*Expects List&lt;FieldValue&gt;*/)
           .build();
  
  TermsQuery idTerms = new TermsQuery.Builder()
          .field(&quot;id&quot;)
          .terms(termsQueryField)
          .build();
  
  Query idQuery = new Query.Builder()
          .terms(idTerms)
          .build();
  
  BoolQuery boolQuery = new BoolQuery.Builder()
          .must(idQuery)
          .build();
  
  Query query = new Query.Builder()
          .bool(boolQuery)
          .build();
  
  SearchRequest searchRequest = new SearchRequest.Builder()
          .index(indexName)
          .query(query)
          .build();
  
  </code></pre>
  <p>I can add the <code>termQuery</code> options for single values but I could not find a way to add a list to the query.</p>
  <p>I've came across with <code>TermsQuery</code> but that requires the values to be set as a <code>List&lt;FieldValue&gt;</code> so that's not very helpful.</p>
  <p>Note: I know I can use lambda expressions for constructing these objects but I am trying to be as verbose as possible until I figure out how to use the new client.</p>