Search code examples
vespa

How to find distinct records in vespa.ai?


We have a use case where we need to find out the distinct (unique) records.

We have 5 different keys in a document they are all searchable, need to find the distinct records using one key.

I also need to implement pagination on that distinct records.


Solution

  • See https://docs.vespa.ai/documentation/grouping.html. The Vespa grouping language also supports pagination.

    Example:

    select ... | all(group(key) max(10) each( max(3) each(output(summary())))) 
    

    Will group hits by the key field, display at max 10 unique key values and for each unique key value render 3 best hits. Groups are by default ordered by the max relevancy of a hit in the group. When using max() you'll be able to paginate using the continuation parameter to fetch more groups or more hits.