How to do multiple filter query in Elasticsearch using Java?
<p>I have build a web app on top of elasticsearch. I would like to do a multiple filter using Java. </p>

<p>Elasticsearch Query:</p>

<pre><code>{
  "query": {
    "bool": {
      "must": [
        {"match": {
          "T": "TEXT"},
          "match": {
            "new_content": "TEXT"
          }
        },

      ],
      "filter": {
        "term": {
          "collection1": "xyz"
        },
        "term": {
          "collection2": "abc"
        }
</code></pre>

<p>I want to filter the query such that it should filter on the same field <code>collection</code> with two different values(for eg,"xyz" and "abc")</p>

<p>Right now, I have coded a Java program for the single filter.</p>

<pre><code>BoolQueryBuilder boolQuery = QueryBuilders.boolQuery()
                .must(QueryBuilders.simpleQueryStringQuery(query).field("newContent").field("T"))
                .filter(QueryBuilders.termQuery(Collection1, "abc"));
</code></pre>

<p>How should I filter a query on a same field for multiple values?</p>

<p><strong>Edit</strong>: </p>

<p>Actually in my web app, I have extracted the value of the collection as:</p>

<pre><code>String[] Collection=request.getParameterValues("site");
</code></pre>

<p>Collection is the field in my elasticsearch documents. Suppose <code>Collection[0]</code> is germany_collection(value:true), <code>Collection[1]</code> is usa_collection(value:true). I want to write a query which filters my documents such that I will get results when germany_collection:true and usa_collection:true. </p>

<p>This is my original program:</p>

<pre><code>public StringBuffer getJson(String query, String start, String [] Collection{
Client client = TransportClient.builder().build()
                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"), 9300));

        BoolQueryBuilder boolQuery = QueryBuilders.boolQuery()
                .must(QueryBuilders.simpleQueryStringQuery(query).field("newContent").field("T"))
                .filter(QueryBuilders.termQuery(Collection[0], "true").filter(QueryBuilders.termQuery(Collection[1], "true");
</code></pre>

<p>But when I did applied this filter, I am getting this error <code>The method filter(TermsQueryBuilder) is undefined for the type TermsQueryBuilder</code>. It says add cast to method reciever.</p>