# Elasticsearch query directly through Java API without creating relevant API objects

**URL:** <https://discuss.elastic.co/t/elasticsearch-query-directly-through-java-api-without-creating-relevant-api-objects/80028>\
**Category:** Elasticsearch\
**Created:** [March 26, 2017, 8:01am UTC](https://discuss.elastic.co/t/elasticsearch-query-directly-through-java-api-without-creating-relevant-api-objects/80028 "2017-03-26T08:01:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aravindtga](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@aravindtga](https://discuss.elastic.co/u/aravindtga)\
**Post date:** [March 26, 2017, 8:01am UTC](https://discuss.elastic.co/t/elasticsearch-query-directly-through-java-api-without-creating-relevant-api-objects/80028/1 "2017-03-26T08:01:54Z")

</div>

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

```auto
{
	"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,

```auto
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

---

<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:** [March 31, 2017, 6:21am UTC](https://discuss.elastic.co/t/elasticsearch-query-directly-through-java-api-without-creating-relevant-api-objects/80028/2 "2017-03-31T06:21:03Z")

</div>

Have a look at [https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-compound-queries.html#java-query-dsl-bool-query](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.

---

<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:** [April 28, 2017, 6:21am UTC](https://discuss.elastic.co/t/elasticsearch-query-directly-through-java-api-without-creating-relevant-api-objects/80028/3 "2017-04-28T06:21:49Z")

</div>

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