Elasticsearch query directly through Java API without creating relevant API objects

I am using the following elasticsearch query to fetch the details,

{
	"query": {
		"bool": {
			"must": {
        		"match_all": {}
    		},
			"filter": {
				"bool": {
					"should": [
					{"match": {
						"val": "GET"
					}}]
				}
			}
		}
	}
}

It is working fine and given the result as required.

I want to execute the same query through java and get the same results and tried the following,

getClient().prepareSearch(esIndex) .setQuery(QueryBuilders.queryStringQuery(QUERY)).execute().actionGet();

It is not returning the data and throw some query format wrong exception as well.

Is there any Java API available using which the same query can be executed?

NOTE: There is a possibility available to create the boolquery and aggregation builders in java api and execute the same. I am just curious to find a way to execute this query directly through elasticsearch java api

Have a look at https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-compound-queries.html#java-query-dsl-bool-query

But may be this is not exactly what you are looking for.

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