Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Keen.io have a limit keyword or equivalent?

Tags:

keen-io

All,

Using Keen.io to pull some analytics. I allow user input to specify start and end times, but I'm not able to find something equivalent to a "limit" parameter such as can be found for SQL queries. If a user specifies a large enough range, this can result in way too much data coming back.

Does Keen.io have a way to pull back the first "x" records?

bower.json

"keen-js": "^3.4.1",

like image 258
Will Lovett Avatar asked Nov 13 '17 01:11

Will Lovett


2 Answers

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.

like image 126
jandwiches Avatar answered Nov 04 '22 22:11

jandwiches


Looking at the docs it looks like the simplest way to limit results over a timeframe is to group results into [interval][1]s.

It's not a perfect solution in that you end up with grouped data instead of individual records, but does give a guarantee that the results are limited

like image 40
coagmano Avatar answered Nov 04 '22 23:11

coagmano