Search code examples
timekeen-io

Event within timeframe (without date) in Keen.io


Is there a way to query for all events that have occurred between 12am - 9am on any date?


Solution

  • The only way to accomplish this using keen.timestamp is to run a query for each individual day with a timeframe of 12:00 AM to 9:00 AM (or a filter for the same timespan) for that particular day. Filtering by keen.timestamp requires both a date and a time which prevents you from using time separately.

    That being said, you could adjust your data model to include another property called hour_of_day, and then filter on it where it's between 0 and 9 (assuming a 24 hour clock). That way you could specify any timeframe you like in your query.

    Sample event:

    {
      "action":"signed_up".
      "ip_address":"11.22.33.44",
      "hour_of_day":6
    }
    

    I don't recommend unbounded queries though (queries without a timeframe) as your performance will suffer. All data is indexed on keen.timestamp which makes queries that specify timeframes much faster than those that don't.