There is a new Keen IO API feature released today which allows you to limit your query result to get your "top x results" and have the results ordered by ascending or descending as well. order_by works similar to the currently existing group_by feature -- you will call order_by in your query.
Define a direction to sort all of your query's results in either ASC or descending order (default ordering is ascending). And use limit to tell the API the number of results you'd like returned - whether that is your top 5 or bottom 5 results.
Order By Docs: https://keen.io/docs/api/#order-by
Here's sample JavaScript to illustrate the newly added order_by API feature:
import Keen from 'keen-js';
const client = new Keen({
projectId: 'PROJECT_ID',
readKey: 'READ_KEY'
});
client
.query('count', {
event_collection: 'logins',
group_by: 'user.email',
order_by: {'property_name': 'result', 'direction': 'DESC'},
limit: '5', //this limits your number of results
timeframe: 'this_14_days'
})
.then(res => {
// Handle results
})
.catch(err => {
// Handle errors
});
order_by and limit has been a top requested by customers - thank you for feedback to help with creating tools and features to Keen IO's API.