Query_string in Java API 5.4

(Hrachya Yeghishyan) #1

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\" : \"*\""))

(Hrachya Yeghishyan) #2

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. :slight_smile:

(David Pilato) #3

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

Note that this is wrong:

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

It should be:


(Hrachya Yeghishyan) #4

Thank you very much @dadoonet

(system) #5

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