Category: How do I do X?
Updated

This solution is summarized from an archived support forum post. This information may have changed. If you notice an error, please let us know in Discord.

Get list of distinct values from existing query result set

Issue

I have an Elasticsearch database query and I want to generate a list of unique values for a specific field. I tried using the "collapse" method but couldn't get it to work. I want to work with the existing results on the client-side and not re-run the query on the server.

Resolution

The user had an elasticsearch database query that returned a list of records. They wanted to generate a list of distinct values for the author_id field without duplications. One solution involved using the “terms” aggregation to get a count of each unique author_id value. This could be done by adding an aggregation to the query with a "terms" key and a "field" key specifying the author_id field. Another solution involved using the "collapse" method to collapse the search results based on the author_id field, which would return an array of records for each unique author_id value. The user noted that the results could be restricted to reduce the amount of data returned.