# Java API, using query\_string for aggregates

**URL:** <https://discuss.elastic.co/t/java-api-using-query-string-for-aggregates/33897>\
**Category:** Elasticsearch\
**Created:** [November 5, 2015, 5:05pm UTC](https://discuss.elastic.co/t/java-api-using-query-string-for-aggregates/33897 "2015-11-05T17:05:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aliaspooryorik](https://avatars.discourse-cdn.com/v4/letter/a/94ad74/32.png) [@aliaspooryorik](https://discuss.elastic.co/u/aliaspooryorik)\
**Post date:** [November 5, 2015, 5:05pm UTC](https://discuss.elastic.co/t/java-api-using-query-string-for-aggregates/33897/1 "2015-11-05T17:05:36Z")

</div>

Hello,

I originally posted this question on [StackOverflow](http://stackoverflow.com/questions/33549376/elasticsearch-2-0-java-api-aggregate-filter-with-query-string) so hope I'm not generating noise by posting it here as well.

I'm running on ElasticSearch 2.0 connecting via the Java API. I've got the following query working via the REST API and can't figure out how to do this using the Java API.

```
{
  "query": {
    "query_string": {
      "query": "myfield:*"
    }
  },
  "aggs" : {
    "foo_low": {
      "filter" : {
        "query" : {
          "query_string" : {
            "query": "myfield:[1 TO 5]"
          }
        }
      }
    },
    "foo_high": {
      "filter" : {
        "query" : {
          "query_string" : {
            "query": "myfield:[6 TO 10]"
          }
        }
      }
    }
  }
}

```

I've had a look at the examples using the addAggregation method but not sure how to pass in the query\_string part.

As a bit of a background, was originally using Solr so have multiple Solr facet queries that need to be translated to ElasticSearch. The facet queries are a bit more complicated then I've shown in the example, with multiple fields referenced in each Solr facet query.

Any ideas gratefully received! Thanks.

Original SO question:

> <https://stackoverflow.com/questions/33549376/elasticsearch-2-0-java-api-aggregate-filter-with-query-string>

---

<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:** [July 5, 2017, 11:40pm UTC](https://discuss.elastic.co/t/java-api-using-query-string-for-aggregates/33897/2 "2017-07-05T23:40:18Z")

</div>


