Best way to load an elastic query and manipulate it


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:

 val searchRequest = SearchRequest.of {

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!

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?

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