# Query\_string in Java API 5.4

**URL:** <https://discuss.elastic.co/t/query-string-in-java-api-5-4/120456>\
**Category:** Elasticsearch\
**Created:** [February 19, 2018, 12:59pm UTC](https://discuss.elastic.co/t/query-string-in-java-api-5-4/120456 "2018-02-19T12:59:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hrachya\_Yeghishyan](https://avatars.discourse-cdn.com/v4/letter/h/a9a28c/32.png) [@Hrachya\_Yeghishyan](https://discuss.elastic.co/u/Hrachya_Yeghishyan)\
**Post date:** [February 19, 2018, 12:59pm UTC](https://discuss.elastic.co/t/query-string-in-java-api-5-4/120456/1 "2018-02-19T12:59:59Z")

</div>

Is there an equivalent of the query\_string for the ES Java API 5.4, as it look like that queryString is unavailable in this version?  
Also there isn't anything descriptive about the queryStringQuery in the documentation of the Java API.  
I'm passing as an argument exactly what I'd write in case of using -curl to the method queryStringQuery, and it results in SearchPhaseExecutionException.  
My aim is to get all the values of a certain field (crash\_case in this case). For that I'm doing a query\_string query and then perform an aggregation, and get the keys from the buckets.  
Here is the -curl command that works just fine:

```
{
    "query" : { "query_string" : {"query" : "*"} },
    "aggs" : {
      "tags" : { "terms" : {"field" : "crash_case.keyword"} }
    }
  }

```

And this is the java code that should behave in a similar fashion in my opinion:

```
SearchResponse response = client.prepareSearch("closed-cases")
                    .setQuery(QueryBuilders.queryStringQuery("\"query\" : \"*\""))
                    .addAggregation(AggregationBuilders.terms("check").field("crash_case.keyword"))
                    .execute()
                    .actionGet();
```

---

<div class="post-metadata">

**Author:** ![Hrachya\_Yeghishyan](https://avatars.discourse-cdn.com/v4/letter/h/a9a28c/32.png) [@Hrachya\_Yeghishyan](https://discuss.elastic.co/u/Hrachya_Yeghishyan)\
**Post date:** [February 19, 2018, 2:41pm UTC](https://discuss.elastic.co/t/query-string-in-java-api-5-4/120456/2 "2018-02-19T14:41:21Z")

</div>

For this very case I have preferred a more solid solution. Instead of the query\_string I just use a matchAllQuery(). Nevertheless, it'd be still interesting to know how one can deal with the method queryStringQuery(), and what kind of String it expects to receive. 🙂

---

<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:** [February 19, 2018, 2:47pm UTC](https://discuss.elastic.co/t/query-string-in-java-api-5-4/120456/3 "2018-02-19T14:47:41Z")

</div>

It exists: [https://artifacts.elastic.co/javadoc/org/elasticsearch/elasticsearch/5.6.7/org/elasticsearch/index/query/QueryStringQueryBuilder.html](https://artifacts.elastic.co/javadoc/org/elasticsearch/elasticsearch/5.6.7/org/elasticsearch/index/query/QueryStringQueryBuilder.html)

Note that this is wrong:

```auto
.setQuery(QueryBuilders.queryStringQuery("\"query\" : \"*\""))

```

It should be:

```auto
.setQuery(QueryBuilders.queryStringQuery("*"))

```

---

<div class="post-metadata">

**Author:** ![Hrachya\_Yeghishyan](https://avatars.discourse-cdn.com/v4/letter/h/a9a28c/32.png) [@Hrachya\_Yeghishyan](https://discuss.elastic.co/u/Hrachya_Yeghishyan)\
**Post date:** [February 19, 2018, 3:11pm UTC](https://discuss.elastic.co/t/query-string-in-java-api-5-4/120456/4 "2018-02-19T15:11:04Z")

</div>

Thank you very much @dadoonet

---

<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:** [March 19, 2018, 3:11pm UTC](https://discuss.elastic.co/t/query-string-in-java-api-5-4/120456/5 "2018-03-19T15:11:04Z")

</div>

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