Using now() in startkey and endkey

dateToArray() and now() are javascript functions that you can use in the map function, which does the indexing, but not reference when querying.

Don’t build the URL yourself, there’s no way to express what you want directly to the view (which doesn’t have a function interpreter for query time and would just think that “now() - 20” is just another string key).

Use the SDK, and Java, to dynamically create the equivalent of dateToArray(now() - 20) (using Calendar and JsonArray as briefly explained before) then to query the view (it will internally build the URL and all that).

Refer to the documentation of the SDK if you need more information on View querying: developer.couchbase.com/documentation/server/4.1/sdks/java-2.2/querying-views.html