The Data Explorer plugin allows you to make SQL queries against your live database, allowing for up-to-the-minute stats reporting.
After installing the plugin, head to
Click on the “Settings” button, and turn on
data explorer enabled, then return and reload the page.
There should now be a tab in the stacked nav called “Data Explorer”. Select it or head to
/admin/plugins/explorer , then use the + , Import or Run Query buttons to get started.
On a fresh install, the data explorer now ships with a bunch of useful queries that can help you draw insights from your forum’s activity. Open any query and click
Run Query to try it out.
Here's what the stock queries look like.
Note: Default queries are picked up from this file: discourse-data-explorer/queries.rb at master · discourse/discourse-data-explorer · GitHub
If you have an awesome query that you want everyone to have, make a PR just like this one.
Default queries cannot be edited, feel free to copy the sql and paste it into a new query if you’d like to modify them.
Add your own queries
For an example, let’s import one that I wrote. Download this file, then open the import dialog and select the file to be uploaded or paste the query in the text box. Click Import to save it and then click Run Query to see the results.
most-common-likers.dcquery (1).json (442 Bytes)
Looks like all of the Discourse developers like each other quite a bit
I don’t know any SQL, where do I find more queries?
Our community has got you covered!
Import as many queries as you like from here: What cool data explorer queries have you come up with?
When you click any of the Edit buttons on a query view, or start a new Explorer Query, you are presented with a screen like the one below:
The top two boxes are the name and description of the query. The name is what you’re selecting in the dropdown box, and the description should be used for things like explaining what to put in the query parameters or to describe what data is being queried.
The left pane is where you write the SQL query. Minor syntax highlighting and checking is provided.
Declaring Parameters in your query
Lets modify our example by using a parameter instead of hard-coding values. If you declare a variable as shown below, a text field will show up where you can input different values! Try it out!
-- [params] -- int :limit = 100 WITH pairs AS ( SELECT p.user_id liked, pa.user_id liker FROM post_actions pa LEFT JOIN posts p ON p.id = pa.post_id WHERE post_action_type_id = 2 ) SELECT liker liker_user_id, liked liked_user_id, count(*) FROM pairs GROUP BY liked, liker ORDER BY count DESC LIMIT :limit
Searching in your queries list
If you’ve accumulated too many awesome queries, no problem! The search bar can help you filter through titles and descriptions.
- If there are more than 1000 results, Run Query will return only the first 1000. Clicking Export will let you download all the results with a much higher limit.
If you’re on a hosted Discourse forum and the data explorer doesn’t show up at /admin/plugins, email us at email@example.com to ask us to add it for you.