Query by Multiple Values by Custom Field with Custom number of results for each field


Suppose I have a custom field called Category and it is assigned with A or B or C values.

Now I need to grab
x number of A Category (4 A)
y number of B Category (3 B)
z number of C Category (2 C) results.

or at least
the same number of A, B and C Category results (5 A, 5 B, and 5 C Category results)

Is there any possible way to satisfy above in Single API Call/ Any better approach rather than calling API thrice?

Thanks in Advance…!

Is this helpful?

Hey @saddagatla-contracto

It’ll depend on the technology that you’re working on.

If I understand correctly, you want to retrieve all categories with the total count of documents linked to them. Is that right?

e.g Let’s say x,y, and z are documents of the type ‘Article’. If you run a predicate like this it will give you all articles of a related to a given category

const article = (await $prismic.api.getByUID(‘article’, params.uid)).data

const categoryId = article.category_field.id

const categoryArticles = await $prismic.api.query([
  $prismic.predicates.at(‘document.type’, ‘article’),
  $prismic.predicates.at(‘my.post.category_field’, categoryId)

If you’re working with GraphQL, you could do a query that does something similar. You’d call allArticles and then filter them by the category field that matches the given ID:

query {
  allArticles(where: {category:"XniT7xIAACgAk6zG"}) {

Thanks for the link.
But this isn’t helpful.

Thanks for the reply.
I am using JavaScript (NodeJS env) to query Prismic.

I think you didn’t get my question Correctly,
Suppose I have a Document Type called blog-type and it is having a custom filed called Category in it. (Assigning A or B or C Values to this category field)

I have 100 articles of blog-type Doctype. Out of which 40 are of A category, 30 are of B Category, and rest 20 are of C category articles.

I need a single query to retrieve 5 A Category, 7 B Category, and 9 C Category blog-type Category type Articles.
I need a query to retrieve 5 number of articles each A, B and C Categories of blog-type Category type Articles.

Hey, returning to our old convo. Queries like this aren't possible just yet in Prismic. You can instead query by the given field that you are using to assign 'categories' to your documents and then filtering out the number of documents that you need to display

This is being tracked as an open feature request.

If you have another use-case for this feature, you can 'Flag' this topic to reopen. Please use the :heart: button to show your support for the feature and check out our Feature Request Guidelines.