How can I get the Json DSL from a Query object in java client

I’m using the last version of OpenSearch (2.4.x) and I want to know if it is possible to get the Json DSL of a query performed. For example:

I have this query in the java client

Query query = new Query.Builder()
                .match(new MatchQuery.Builder()
                        .query(q -> q.stringValue("osx"))

I want to get the DSL equivalent

  "query": {
    "match": {
      "machine.os.keyword": "osx"

There is an index-level setting that allows you to enable query logs. It is set to -1 by default, but you can change it to a nonnegative value: Logs - OpenSearch documentation

Thanks for your response, @wbeckler, but I am looking for a specific function in the OpenSearch java client to get the JSON version of an elasticsearch query from a Query object as I say in the example above