cts.documentQuery(cts.uriMatch("/directory/*/folder/*.xml"))
Is this what you are expecting? This is the server side javascript (XQuery) equivalent of what you have asked.
If you want to pass a serialized query, you should first execute cts:uri-match("/directory/*/folder/*.xml")
and then enclose the results into cts:document-query
as shown below
<cts:document-query xmlns:cts="http://www.w3.org/2000/xmlns/">
<cts:uri>/directory/2019/folder/1.xml</cts:uri>
<cts:uri>/directory/2020/folder/2.xml</cts:uri>
<cts:uri>/directory/2021/folder/3.xml</cts:uri>
</cts:document-query>
Best approach is to create a MarkLogic module server-side (in XQuery or JS) and invoke it from JAVA client API (by passing the uri-match string)