# Best way to load an elastic query and manipulate it

**URL:** <https://discuss.elastic.co/t/best-way-to-load-an-elastic-query-and-manipulate-it/341099>\
**Category:** Elasticsearch\
**Created:** [August 18, 2023, 1:38pm UTC](https://discuss.elastic.co/t/best-way-to-load-an-elastic-query-and-manipulate-it/341099 "2023-08-18T13:38:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zer0](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zer0/32/124706_2.png) [@Zer0](https://discuss.elastic.co/u/Zer0)\
**Post date:** [August 18, 2023, 1:38pm UTC](https://discuss.elastic.co/t/best-way-to-load-an-elastic-query-and-manipulate-it/341099/1 "2023-08-18T13:38:41Z")

</div>

Hi,

I am using the Elasticsearch Java client and what I basically want to achieve is the following: Our backend is basically a ES Proxy, so there is an endpoint that takes an ES query as input, adds a clause (to scope the query and apply some restrictions on the documents available to find) and then sends it over to ES, piping the the response from ES through to the user/frontend again.

So the part that I'm struggling with is adding the extra clauses. I know I can construct a SearchQuery via Json:

```auto
 val searchRequest = SearchRequest.of {
     it.withJson(query.byteInputStream())
     it.index("some_index")
}

```

I can see in the inspector that the query is parsed correctly and represented in the SearchQuery object. Sending this to ES also produces the expected results. I don't see how I can manipulate the query inside `searchRequest` after parsing it.

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Zer0](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zer0/32/124706_2.png) [@Zer0](https://discuss.elastic.co/u/Zer0)\
**Post date:** [August 21, 2023, 12:10pm UTC](https://discuss.elastic.co/t/best-way-to-load-an-elastic-query-and-manipulate-it/341099/2 "2023-08-21T12:10:06Z")

</div>

I have found a solution on SO (questions/52376257/elasticsearch-jest-client-add-condition-to-json-query) where they parse/deconstruct the original query with Jacksons ObjectMapper and then build a new query with parts of it.  
Is this still the only option?

---

<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:** [September 18, 2023, 12:10pm UTC](https://discuss.elastic.co/t/best-way-to-load-an-elastic-query-and-manipulate-it/341099/3 "2023-09-18T12:10:44Z")

</div>

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