# How to use WrapperQuery in new Java API client 8.4.3 to fire a raw elasticsearch query?

**URL:** <https://discuss.elastic.co/t/how-to-use-wrapperquery-in-new-java-api-client-8-4-3-to-fire-a-raw-elasticsearch-query/319727>\
**Category:** Elasticsearch\
**Created:** [November 24, 2022, 9:36am UTC](https://discuss.elastic.co/t/how-to-use-wrapperquery-in-new-java-api-client-8-4-3-to-fire-a-raw-elasticsearch-query/319727 "2022-11-24T09:36:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![p4charu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/p4charu/32/113392_2.png) [@p4charu](https://discuss.elastic.co/u/p4charu)\
**Post date:** [November 24, 2022, 9:36am UTC](https://discuss.elastic.co/t/how-to-use-wrapperquery-in-new-java-api-client-8-4-3-to-fire-a-raw-elasticsearch-query/319727/1 "2022-11-24T09:36:53Z")

</div>

I'm trying to use WrapperQuery to run a raw query like this

```auto
		String queryStr = "{\n" +
				" \"query\": {\n" +
				" \"bool\": {\n" +
				" \"must\": [\n" +
				" {\n" +
				" \"match\": {\n" +
				" \"type\": \"MyType\"\n" +
				" }\n" +
				" }\n" +
				" ]\n" +
				" }\n" +
				" }\n" +
				"}";
		String encodedString = Base64.getEncoder().encodeToString(queryStr.getBytes());
		Query wq = QueryBuilders.wrapper(w->w.query(encodedString));

```

But get the below error when executing the search.  
`ErrorResponse: {"error":{"col":12,"line":2,"type":"parsing_exception","reason":"unknown query [query]","status":400}`

However, if I remove the "query" element from the raw query JSON, I can execute the wrapper query.  
E.g.

```auto
String queryStr = "{
    "bool": {
      "must": [
        {
          "match": {
            "type": "MyType"
          }
        }
      ]
    }
}"

```

gives me matching results.

Can you please provide an example to run a more complicated raw query having elements outside the "query" element like below:

```auto
String queryStr = "{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "type": "MyChange"
          }
        }
      ]
    },
  "size": 30,
  "from": 0,
  "sort": [
    {
      "change": {
        "order": "desc"
      }
    }
  ]
}
}"

```

Many thanks.

---

<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:** [December 22, 2022, 9:37am UTC](https://discuss.elastic.co/t/how-to-use-wrapperquery-in-new-java-api-client-8-4-3-to-fire-a-raw-elasticsearch-query/319727/2 "2022-12-22T09:37:36Z")

</div>

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