Skip to main content
The top hits aggregation is meant to be used in conjunction with the terms aggregation. It returns the top documents for each bucket of a terms aggregation. For example, the following query answers “what are top 3 results sorted by created_at for each rating category?”
Expected Response
The sort value returned by the aggregation is Tantivy’s internal sort ID and should be ignored. To get the actual fields, pass a list of fields to docvalue_fields. If a text or JSON field is passed to docvalue_fields, it must be indexed with the literal tokenizer. To specify an offset, use from:
If multiple fields are passed into sort, the additional fields are used as tiebreakers:
See the Tantivy documentation for all available options.