Download Markdown

Analytics Queries (Preview)

By the end of this page you can combine measures, groupings and filters freely and get trends, rankings and distributions directly.

Results are aggregated rows, with no bodies; they can’t be used as a list of documents. For raw records, use browse, bulk exports or the change feed.

Note: This is a Preview feature. Sources and endpoints marked “coming soon” are still being validated; don’t depend on them in production.

Step 1: See what you can query

Bash
curl -sS "$WHALE_BASE_URL/v1/analytics/meta" \
  -H "Authorization: Bearer $WHALE_API_KEY"

Returns the sources your application can query, with each source’s measures and dimensions:

JSON
{
  "sources": [
    {
      "name": "sentiment",
      "description": "Latest sentiment analysis per document",
      "measures": [
        {"name": "sentiment.documents", "title": "Documents", "type": "number"},
        {"name": "sentiment.score_avg", "title": "Average sentiment score", "type": "number"}
      ],
      "dimensions": [
        {"name": "sentiment.source_platform", "title": "Platform", "type": "string"},
        {"name": "sentiment.label", "title": "Sentiment (negative / neutral / positive)", "type": "string"},
        {"name": "sentiment.published_at", "title": "Published at", "type": "time"}
      ]
    }
  ]
}

This endpoint is authoritative: only the sources and members it lists can be queried.

Step 2: Run a query

Weekly English document counts and average sentiment in October, by platform and sentiment:

Bash
curl -sS "$WHALE_BASE_URL/v1/analytics/query" \
  -H "Authorization: Bearer $WHALE_API_KEY" \
  -H "Content-Type: application/json" \
  --data '{
    "measures": ["sentiment.documents", "sentiment.score_avg"],
    "dimensions": ["sentiment.source_platform", "sentiment.label"],
    "timeDimensions": [{
      "dimension": "sentiment.published_at",
      "granularity": "week",
      "dateRange": ["2026-10-01", "2026-10-31"]
    }],
    "filters": [{"member": "sentiment.language", "operator": "equals", "values": ["en"]}],
    "order": {"sentiment.documents": "desc"},
    "limit": 100
  }'
JSON
{
  "data": [
    {
      "sentiment.source_platform": "reddit",
      "sentiment.label": "negative",
      "sentiment.published_at.week": "2026-10-06T00:00:00.000",
      "sentiment.documents": "1840211",
      "sentiment.score_avg": "-0.7461"
    }
  ],
  "refreshed_at": "2026-11-03T12:05:21Z"
}

Numbers are returned as strings so large integers keep their precision.

FieldMeaning
measuresRequired, 1 to 10 measures
dimensionsUp to 5 grouping dimensions
timeDimensionsRequired, exactly one: the time dimension, optional granularity (day, week, month, quarter, year) and dateRange
dateRange["YYYY-MM-DD", "YYYY-MM-DD"], both days inclusive, UTC. Up to 92 days (content_live 31, metric_growth 7). Relative ranges like “last 7 days” aren’t supported
filtersEach has member, operator and values. Operators: equals, notEquals, contains, gt, gte, lt, lte, set, notSet
orderSorting, such as {"sentiment.documents": "desc"}
limit, offsetDefault 1000 rows, up to 10000; offset up to 100000

All measures, dimensions and filters in one query must come from the same source.

Choose a source

SourceOne row isTime dimensionField access needed
new_documentsA newly ingested documentpublished_at or stored_at (ingest time)identity
metrics_latestA document’s latest metricspublished_atmetrics
metric_historyOne collection’s metrics, since 2026-07-01metric_time (collection time)metrics
sentimentA document’s latest sentimentpublished_ataffect
affect_labelsA document’s latest emotion (kind=emotion) and intent (kind=intent) labelspublished_atEmotions need affect, intents need intents
entitiesEntity mentions, since 2026-10-29day (analysis date)entities
content_liveOne row per document with metrics, channel, sentiment, emotion, intent and author, for cross-analysis and rankingspublished_atidentity, plus the table below
metric_growth (coming soon)Each document’s metric change within a windowwindow (collection time)metrics

content_live also needs access for the members you use:

MembersAlso needs
Metrics (view_count_*, like_count_*, score_* and so on)metrics
sentiment, sentiment_score_avg, emotionaffect
intentintents
author_id, author_name, author_followersauthor
channelmetadata

Access limits:

  • Access limited by region: no source can be used.
  • Access limited by language: only sentiment, affect_labels, entities and content_live.
  • Access limited by publish time: not metric_history, entities or metric_growth.

Common questions

Top 10 by likes

Use content_live, grouped by document_id and sorted:

JSON
{
  "measures": ["content_live.like_count_max"],
  "dimensions": ["content_live.document_id", "content_live.author_name", "content_live.source_platform"],
  "timeDimensions": [{"dimension": "content_live.published_at", "dateRange": ["2026-10-28", "2026-11-03"]}],
  "order": {"content_live.like_count_max": "desc"},
  "limit": 10
}

To rank authors or channels, switch the dimension to content_live.author_name or content_live.channel and use documents or *_sum.

Look at distributions, not just averages

*_p50, *_p90 and *_p99 are approximate medians and percentiles, available only in content_live. Compare them with the average so a few viral posts don’t skew the picture:

JSON
{
  "measures": ["content_live.like_count_p50", "content_live.like_count_p90", "content_live.like_count_avg"],
  "dimensions": ["content_live.source_platform"],
  "timeDimensions": [{"dimension": "content_live.published_at", "dateRange": ["2026-10-01", "2026-10-31"]}]
}

Sentiment versus likes

In content_live, metrics sit in the same row as sentiment, emotion, intent and channel. For example, average likes by sentiment: measure content_live.like_count_avg, dimension content_live.sentiment. Up to 31 days per query; query longer periods month by month.

Fastest-growing documents (coming soon)

metric_growth takes each document’s last minus first collected value within the window, counting only documents collected at least twice:

JSON
{
  "measures": ["metric_growth.like_count_gain_max"],
  "dimensions": ["metric_growth.document_id", "metric_growth.source_platform"],
  "timeDimensions": [{"dimension": "metric_growth.window", "dateRange": ["2026-11-01", "2026-11-03"]}],
  "order": {"metric_growth.like_count_gain_max": "desc"},
  "limit": 20
}

Growth can be negative, for example when likes are withdrawn.

Entities versus metrics (coming soon)

In entities, *_avg and *_sum are the latest metrics of documents mentioning the entity. For example, filter entities.entity to one entity and group by entities.entity_sentiment to see entities.like_count_avg.

Analyze only search results (coming soon)

Narrow documents with a keyword first, then run a content_live query on them. For example, “sentiment and median likes for documents mentioning iPhone”:

Bash
curl -sS "$WHALE_BASE_URL/v1/analytics/search-query" \
  -H "Authorization: Bearer $WHALE_API_KEY" \
  -H "Content-Type: application/json" \
  --data '{
    "search": {"query": "iphone", "source_platforms": ["reddit"], "max_documents": 1000},
    "query": {
      "measures": ["content_live.documents", "content_live.like_count_p50"],
      "dimensions": ["content_live.sentiment"],
      "timeDimensions": [{"dimension": "content_live.published_at", "dateRange": ["2026-10-05", "2026-11-03"]}]
    }
  }'
FieldMeaning
search.queryKeyword, same rules as keyword search; takes the top max_documents by relevance
search.source_platforms, search.languagesOptional; narrow the search
search.published_from, search.published_toOptional, RFC 3339 times
search.max_documentsDocuments included; default and maximum 1000
queryA content_live query, same rules as above

The response adds documents_matched: the number of documents found and analyzed.

How fresh the data is

refreshed_at is when the rollup last refreshed:

SourceRefresh
metric_history, new_documents by ingest timeHourly, last two days
entitiesEvery 6 hours, last two days
Other rollupsEvery 6 hours
content_live, metric_growthComputed at query time; no refreshed_at

How measures are computed

  • *_avg average, *_sum total, *_max maximum, *_documents documents that have the metric.
  • Metrics a platform doesn’t provide are empty and excluded from averages and counts. See the field reference for each platform’s metrics.
  • score is the Reddit score (upvotes minus downvotes), not likes.
  • metrics_latest takes each document’s most recent collection.
  • In metric_history, one row is one collection, so a document appears several times; snapshots is the snapshot count. Use metrics_latest to count per document.
  • new_documents counts each document once, at first ingest.
  • entities counts mentions extracted from each version; entity is the normalized name. When one document mentions the same entity with different attitudes, each counts once. Entity types are in sentiment, entities & intents.
  • In content_live, sentiment, emotion and intent come from the latest analysis; emotion and intent take the top-scoring one. channel currently covers Reddit subreddits only.
  • When emotion or intent isn’t clear, the label is none.

When something fails

  • 422 analytics_not_answerable: this combination can’t be answered from the rollups, for example hourly totals. Change dimensions or granularity.
  • 503 analytics_unavailable: temporarily unavailable, or a direct computation timed out. Shorten the range or add filters, then retry.

Other errors: Error codes.