5

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",

Will Lovett
  • 1,241
  • 3
  • 18
  • 35

2 Answers2

3

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.

jandwiches
  • 487
  • 3
  • 7
1

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

coagmano
  • 5,542
  • 1
  • 28
  • 41
  • 1
    I'll run some tests and see if it was what I was looking for, but thank you for taking a look at this regardless. – Will Lovett Dec 06 '17 at 02:09