# Aggregation with java High Level Rest Client

**URL:** <https://discuss.elastic.co/t/aggregation-with-java-high-level-rest-client/269699>\
**Category:** Elasticsearch\
**Created:** [April 9, 2021, 11:19am UTC](https://discuss.elastic.co/t/aggregation-with-java-high-level-rest-client/269699 "2021-04-09T11:19:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![adelDz](https://avatars.discourse-cdn.com/v4/letter/a/ac91a4/32.png) [@adelDz](https://discuss.elastic.co/u/adelDz)\
**Post date:** [April 9, 2021, 11:19am UTC](https://discuss.elastic.co/t/aggregation-with-java-high-level-rest-client/269699/1 "2021-04-09T11:19:08Z")

</div>

Hello, How to convert this Query Sql with java High Level Rest Client

// select count(\*) from Customer group by Last\_Name, First\_Name, City

Thank you in advance

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 12, 2021, 10:30am UTC](https://discuss.elastic.co/t/aggregation-with-java-high-level-rest-client/269699/2 "2021-04-12T10:30:38Z")

</div>

Welcome!

```auto
select count(*) from Customer group by Last_Name, First_Name, City

```

Is most likely the same as

```auto
select count(*) from Customer

```

Is that what you want?

But anyway my advice would be first to write the elasticsearch query.  
You can get it by using [the translate API](https://www.elastic.co/guide/en/elasticsearch/reference/current/sql-translate.html) like:

```auto
DELETE customer
PUT customer
{
  "mappings": {
    "properties": {
      "City": { "type": "keyword" },
      "First_Name": { "type": "keyword" },
      "Last_Name": { "type": "keyword" }
    }
  }
}
POST customer/_doc
{
  "Last_Name": "foo", 
  "First_Name": "bar",
  "City": "somewhere"
}
POST _sql/translate
{
  "query": "select count(*) from customer"
}
POST _sql/translate
{
  "query": "select count(*) from customer group by Last_Name, First_Name, City"
}

```

Then adapt the result to the java High Level Rest Client.

---

<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:** [May 10, 2021, 10:30am UTC](https://discuss.elastic.co/t/aggregation-with-java-high-level-rest-client/269699/3 "2021-05-10T10:30:50Z")

</div>

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