title: Build ElasticSearch Query using org.elasticsearch:elasticsearch java library
body: <p>I want to build the following ES query using BoolQueryBuilders and Aggregator, but I am unable to do that.</p>
  <pre><code>{
    &quot;size&quot;: 0,
    &quot;query&quot;: {
      &quot;bool&quot;: {
        &quot;should&quot;: {
          &quot;bool&quot;: {
            &quot;filter&quot;: [
              {
                &quot;terms&quot;: {
                  &quot;country&quot;: [
                    &quot;France&quot;,
                    &quot;China&quot;
                  ]
                }
              },
              {
                &quot;term&quot;: {
                  &quot;lang&quot;: &quot;en&quot;
                }
              }
            ]
          }
        }
      }
    },
    &quot;aggs&quot;: {
      &quot;group_by_country&quot;: {
        &quot;terms&quot;: {
          &quot;field&quot;: &quot;country&quot;,
          &quot;size&quot;: 0
        },
        &quot;aggs&quot;: {
          &quot;top_hits_country&quot;: {
            &quot;top_hits&quot;: {
              &quot;size&quot;: 1
            }
          }
        }
      }
    }
  }
  </code></pre>
  <p>I am able to build this query without the aggregator, in the following manner -</p>
  <pre><code>BoolQueryBuilder innerEntityQueryBuilder = new BoolQueryBuilder();
          
  BoolQueryBuilder queryBuilder = new BoolQueryBuilder()
                      .filter(QueryBuilders.termsQuery(&quot;country&quot;, countries)) 
                      .filter(QueryBuilders.termQuery(&quot;lang&quot;, &quot;en&quot;)); 
  innerEntityQueryBuilder.should(queryBuilder);
  </code></pre>
  <p>How do I add the aggregate part as well?</p>