RESTful API Pagination of Results?

85 views
Skip to first unread message

Jeffrey Schultz

unread,
Apr 9, 2021, 6:04:25 PM4/9/21
to dotCMS User Group
Hello,

Is there a way to get the total count of paginated results from a query, so that we can set up paging within a REACT UI? We need the total number of results so that we know how many pages of data there are based on the limit we requested.

Falzone, Chris

unread,
Apr 12, 2021, 9:02:12 AM4/12/21
to dot...@googlegroups.com
The APIs don't seem to have that (maybe a feature request).  For now, you would have to create a custom API for this.  DotCMS has some capability in the newer versions for creating your own APIs - https://dotcms.com/docs/latest/scripting-api - or a plugin could work by either extending the resource that's there or creating your own custom resource.

Hope that helps!

On Fri, Apr 9, 2021 at 6:04 PM Jeffrey Schultz <jeffreys...@gmail.com> wrote:
Hello,

Is there a way to get the total count of paginated results from a query, so that we can set up paging within a REACT UI? We need the total number of results so that we know how many pages of data there are based on the limit we requested.

--
http://dotcms.com - Open Source Java Content Management
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dotcms+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/82b1d1e7-1d17-49d5-b328-d095b997369dn%40googlegroups.com.


--

Christopher Falzone

DevOps Engineer

A Q U E N T  /  VITAMIN T

Will Ezell

unread,
Apr 12, 2021, 9:11:47 AM4/12/21
to dot...@googlegroups.com
The elasticsearch endpoint allows for this - it allows you to paginate and also returns the total number of hits based on the query and then the results you are looking for:

curl -H "Content-Type: application/json" -XPOST https://demo.dotcms.com/api/es/search -d '{
    "query" :
    {
        "query_string" :
        {
            "query" : "+path:\\/images*"
        }
    },
    "size":1,
    "from":5
}'


.... json response .... "hits":{"total":{"value":55,"relation":"eq"}







--



382 NE 191st St #92150
Miami, Florida 33179-3899
Main: 
305-900-2001 | Direct: 978.294.9429

   

Will Ezell

unread,
Apr 12, 2021, 9:37:33 AM4/12/21
to dot...@googlegroups.com
Actually, to follow up on my last response, it looks like all the endpoints return the total number of matches.  The "standard" REST api returns the number of total under a property called "resultsSize".  This is the same query as the ES query above

curl -XPOST 'https://demo.dotcms.com/api/content/_search' \
-H 'Content-Type: application/json' \
-d '{
"query": "
+path:/images*",
"sort": "score,modDate desc",
"limit": 1,
"offset": 5
}'


... json response ... "resultsSize":55}




Reply all
Reply to author
Forward
0 new messages