# Query Elasticsearch of java API

**URL:** <https://discuss.elastic.co/t/query-elasticsearch-of-java-api/79612>\
**Category:** Elasticsearch\
**Created:** [March 22, 2017, 3:52pm UTC](https://discuss.elastic.co/t/query-elasticsearch-of-java-api/79612 "2017-03-22T15:52:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![korsdecaying](https://avatars.discourse-cdn.com/v4/letter/k/dbc845/32.png) [@korsdecaying](https://discuss.elastic.co/u/korsdecaying)\
**Post date:** [March 22, 2017, 3:52pm UTC](https://discuss.elastic.co/t/query-elasticsearch-of-java-api/79612/1 "2017-03-22T15:52:35Z")

</div>

```
"aggs": {
    "2": {
      "terms": {
        "field": "dns.question.type",
        "size": 1000,
        "order": {
          "_count": "desc"
        }

```

I do not understand how to add an aggregation to the Java API elasticsearch request. It is necessary to count the number of documents with the value dns.question.type and return them

```
 SearchResponse response = client.prepareSearch(String.valueOf(QueryBuilders.rangeQuery("@timestamp").gte("now-11d").lt("now-9d")).addAggregation(
AggregationBuilders.terms("")

```

And how do I withdraw after the value of the response such as a Hash Map

---

<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:** [April 19, 2017, 3:53pm UTC](https://discuss.elastic.co/t/query-elasticsearch-of-java-api/79612/2 "2017-04-19T15:53:18Z")

</div>

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