Discourse 数据浏览器

:discourse2: 摘要 Discourse 数据资源管理器允许您对实时数据库执行 SQL 查询,从而实现实时统计报告。
:open_book: 安装指南 此插件已包含在 Discourse 核心中。无需单独安装该插件。

:information_source: 如果您正在寻找自定义查询的示例或支持,可以在我们的 #data-reporting 类别下查找带有 sql-query 标签的大量主题。如果没有适合您特定需求的内容,请随时创建新主题向社区寻求帮助。:memo: 查询帮助

:discourse2: 由我们托管?此插件可在我们的商业版和企业版计划中使用。Data Explorer | Discourse - Civilized Discussion

安装插件后,前往 /admin/plugins

de1

点击“设置”按钮,启用 data explorer enabled,然后返回并刷新页面。
此时,堆叠导航栏中应会出现一个名为“数据资源管理器”的选项卡。选择它,或前往 /admin/plugins/discourse-data-explorer,然后使用 +导入运行 按钮开始操作。

默认查询

在全新安装后,数据资源管理器现已内置多个查询,可帮助您从论坛活动中获取洞察。打开任意查询并点击 运行 即可尝试。

以下是默认查询的样子。

注意: 默认查询是从此文件获取的:discourse-data-explorer/lib/discourse_data_explorer/queries.rb at main · discourse/discourse-data-explorer · GitHub

如果您有一个出色的查询,希望所有人都能使用,只需像 这个示例 一样提交 PR 即可。

默认查询无法编辑。如果您想修改它们,请随意复制 SQL 并将其粘贴到新查询中。

编写查询

当您点击查询视图上的任意 编辑 按钮,或开始一个新的资源管理器查询时,您会看到如下所示的界面:

顶部的两个框是查询的名称和描述。名称是您在下拉框中选择的内容,描述应用于解释查询参数的输入内容,或描述正在查询的数据。

左侧窗格用于编写 SQL 查询。系统提供轻微的语法高亮和检查功能。

自动运行查询

虽然您始终可以通过点击 运行 按钮来运行查询,但通过在 URL 中添加 run 参数,可以在加载查询时节省时间。

例如:/admin/plugins/discourse-data-explorer/queries/123?run

当此参数添加到 URL 时,查询将在页面加载时立即运行,因此您无需点击 运行 按钮即可查看结果。这对于频繁运行的查询特别有用,您可以将其加入书签,或在侧边栏中添加包含 run 参数的链接,实现一键生成报告。

导入查询

举个例子,让我们导入一个我编写的查询。下载此文件,然后打开导入对话框,选择要上传的文件,或将查询粘贴到文本框中。点击“导入”保存,然后点击 运行 查看结果。

most-common-likers.dcquery (1).json (442 字节)

看来所有 Discourse 开发人员都非常喜欢彼此 :heart:

搜索查询

如果您积累了太多出色的查询,没关系!搜索栏可以帮助您按标题和描述进行筛选。

允许非工作人员组运行查询

您可以将特定组(包括版主)添加到查询中,以授予他们访问权限:

保存后,您可以在该特定组的“报告”选项卡下的组页面中找到它:

点击任意查询以打开它,然后点击 运行 按钮查看结果。您还可以点击 加入书签 按钮将组报告加入书签。

使用预定义参数共享查询

如果您在查询中包含了用户定义的参数,您可以共享查询链接,并在 URL 中包含这些参数,这样页面加载时它们将自动填充。

您必须以以下格式在 URL 中包含参数:params={"parameter_name":"value"}。多个参数用逗号分隔。例如:

discourse.example.com/g/my-group/reports/6?params={"param1":"value1","param2":"value2"}

结合上述提到的 run 参数 此处,您可以共享一个带有预定义参数并在加载时自动运行的报告。

结果限制和导出查询

对于大型查询,您可能会注意到 数据资源管理器 显示的行数有限制。默认情况下,限制设置为 1000 行。这是为了防止过于庞大的查询拖慢或干扰您的 Discourse 实例性能。

如果您想绕过此限制,有以下几种选择:

  1. 分页:您可以对结果进行分页。与其尝试一次性返回所有结果,不如编写查询以返回特定范围的结果。然后,您可以调整此范围以查看数据的不同部分。这不会增加限制,但允许您分节查看所有数据。
  2. 增加限制:如果您有权访问 Discourse 服务器并且熟悉修改 Discourse 设置,可以增加限制。但请务必谨慎操作。如果不加小心,增加限制可能会给服务器带来很大负载,尤其是当多个用户同时运行大型查询时。
  3. 下载结果:您也可以选择下载查询结果,而不是直接在 Discourse 中查看。运行查询后,点击 JSONCSV 按钮即可。以 JSON 或 CSV 格式从查询下载的数据将具有更高的结果限制,即 10,000 行。对于编程目的,建议选择 JSON 格式;如果您希望在电子表格应用程序中处理数据,CSV 格式可能更方便。

通常,最好尝试编写更高效的查询,或过滤数据,仅检索您需要的内容,而不是试图绕过限制。

您还可以通过点击 导出 按钮以 .JSON 格式导出 SQL 查询本身。使用此方法导出的查询可以导入到其他 Discourse 站点,或与第三方应用程序一起使用。

查询计划

“包含查询计划”复选框可用于更好地理解和优化您的 SQL 查询。

当您勾选此框并运行查询时,Discourse 将显示用于访问 Discourse 数据库数据的操作序列。这可能包括扫描、连接、排序和其他数据库操作。通过检查查询计划,您可以确切地看到数据库如何执行您的查询。

数据资源管理器教程系列

我们还有一系列专门的 sql-tutorial 关于 数据资源管理器!如果您有兴趣学习更多关于在 Discourse 中编写 SQL 查询的知识,我们强烈推荐阅读此系列中的主题:

121 个赞
Data Explorer Tutorial - Part 1 - Writing Your First Query
Daily graph of user time online
Data Explorer Tutorial - Part 2 - Discourse SQL Basics
Formatting Data Explorer Table Results
Visual forum statistics
Extracting email addresses for a group
Visual map of users
How do I download a record of top posts or most clicked links?
Tags: how can admin see who is following what tags?
Can I see in the statistics which post received the most likes
External Data Analysis
Redesign of use profile
Can staff be able to see real author of anonymous posts
How to search/filter untagged topics
Exporting all Topic titles and IDs?
Retrieving user information via REST API
How to measure active users?
Discourse view file update does not reflect in browser
Scan IP matched accounts
Create report for amount of interactions per user
Where to find User ID information
CSV of all editeds post by moderator
Can I access my Discourse forum database?
How to look up a user based on a user_id?
Can I make a plug-ins to view a certain group of people?
Legal Tools Plugin
[Paid] Data explorer queries for ticketing system use case
Transactional Email Service (Open Source)
Direct connect to the Discourse Database
See what categories new users (& other trust levels) post in most
How can I extract the adminstrative records for a EU GDPR request?
Counting and reporting post views for commercial forum users (so we can charge them per-view)
Top user list public
How do I audit votes for fraudulent behavior
How do I get a list of all users from the API?
Tracking referrals? Encouraging users to invite others?
Display Data Explorer query results in WordPress (with TwigAnything)
Database's Data Model?
Filter or create statistics
How do I add users to a group?
Discourse disk space limits per user?
Masonry Image Gallery
Estimated timeline on a project?
Report on User Fields?
Dashboard - Segment number of Posts and Topics by team
Badge image missing issue
Traditional multi level hierarchy vs flat discourse hierarchy
Is there a Trust Level Permissions Table?
Deleting posts by banned users with < 3 posts?
Calculating "Top" topics in Discourse
Is there a way to Search by Posts with No Staff replies on it
How to use SQL to query discourse database
Specify user by external id
How to check the uniqueness of users in "hot link" badge?
Active users per day
Questions about moving an existing forum to Discourse
Get a user object by username or id javascript
Best Practices on reply-by-email
Most liked reply
Likes on a post
Group forum members based on topics viewed?
The metrics on dashboard, do they include activities from administrators?
Can I access Discourse forum Database to use for PowerBI reporting?
Is there a log of user visits?
Find posts "solved" in specific month
Anonymous User Groups
Any way to NOT send emails when a topic category is changed?
View/read by user or of user's posts?
After server migration the images in posts aren't downloadable anymore
Bug with [code]anything[/code] on a single line by itself
Logo is not appearing showing broken after upload
Configuring how users can create and send invites for others to join your community
Users reporting lots of 502 errors when attempting to post due to "max consecutive replies" check
Wildcard search
What would you like to see on your Discourse 2.0 Admin Dashboard?
TeamSpeak Usergroups Sync
Use tags to duplicate images?
Database Access required for our forum
Updated discourse and now site fails to display
Automatic badge expiration
Looking to switch from Vanilla, and have a few questions
Comment on a question instead of answering it
How to create custom reports
Deleted username but can not use that username in other user
Category Remains Muted after Category is available to Everyone
Can staff see who voters in anonymous polls?
Speak to a Discourse Data Analytic representative
How do I pull a report for a single community member?
Report Links to New Topics by Date?
Excluding Suspended, Silenced and Suspect Users When Exporting
Theme-Component v Plugin: What's the difference
Export topics to Excel
Is there a document introducing the database schema design?
Overview which trust level has which possibilities
Why are some users greyed out?
How to get reports for just a specific category?
How to get posts viewed by a user via APIs?
Reports for group message statistics
TimeStamp of Tag
How we put people in a category?
Is it possible to see the dates of all scheduled topics?
Topic Count Per User for Custom Date?
Searching for unassigned topics
Reports by Discourse
How to see all invites and invite tree?
How can I get the list of Discourse Topic IDs dynamically
How to edit sign up form?
Filter posts with images (gallery view)
Tracking unique contributors
New users who visited this month?
Making report on group membership?
Where to find post contents in the database
Searching All Messages as an Administrator
Are Staff and All Groups Included in Dashboard Reporting?
Deleted user with rails console u.delete -> email still "taken"
First Name, Last Name
User posts export as csv or text
User Messages Inbox Error 500
Description of fields returned by Discourse API
Failed to bootstrap due to out of memory killer
Inviting Feedback for Discourse Wiki ("Morphpedia")
What will happen to my forum if discourse suddenly stopped?
Why aren't warnings easily accessible like suspensions are?
Create a Data Explorer query using the API
Automate the syncing of Discourse queries to Google Sheets
Organization of community Data Explorer queries
Get total list of topics and their view counts from Discourse API
Working around the 10,000 result limit of data explorer?
Selecting the Quarter results in custom way
Create a Report on Profile data
Who marked Solution for Topic
Can you view a 'revised' post after it has been revised
More data from Admin reports
Regarding possibility to use Discourse as an alternative to JIRA or Zendesk
Retrieve latest posts by ID
More granular Discourse metrics?
Dump all conversations in a file and structured data
Login type report / list?
Special role to access dashboard
Best API for All First Posts in a Category
Data Explorer: Posts by Category (Including Subcategories)
Can the period stats use custom time frames to not be limited to only the most recent period?
Tracking who accepted which invite link
Advanced Search: Find posts having staff color
2021: The Year in Review
Filter topics not answered by Staff
Can I download a user database and sort by time viewed?
Category API request downloads all topics
User Data By Date Rage
Browse the Postgres database
How do I extract raw data from my discourse community site?
Some issues with searching (sorting, searching deleted posts and such)
How to Delete Uploaded Files?
How to show badges in the message list?
How to show badges in the message list?
How to find pageview data for a specific topic?
Badges for X Number of Solutions Created?
Permanent deletion bug
Adding SSO after many users already signed up -- how to migrate them?
How could I get voters from a poll?
Notifications from muted categories when mailing list mode is enabled
API: how to get joined at date in user summary
Edit a user preference for everyone or a subset of users
Create a Network chart of your forum - data visualization
Discourse Narrative Bot Data Explorer Queries :robot:
How do I get a report of total topics by subcategory for all subcategories please?
Plugin causing errors during rebuild
User field searching / reporting
Admin dashboard report reference guide
Comment, Question, & Discussion Level Agreement Voting - is there an extension?
How to find deleted posts
SQL query for last created users of the past 30 days
How can I see Survey Results or Responses
Is there a plugin for detecting forum access data?
How to show non-staff posts with zero replies
Viewing all published pages in a single site window
Accessing a user's chat activity
Configure Facebook login for Discourse
Admin Reporting & Analysis: Incremental Changes
Access to OpenID claims data?
How to calculate engagement rate for Discourse?
How to export more than the 10,000 limit?
`/admin/customize/permalinks` only shows ~100 permalinks
Can we delete all 'Automatically Bumped' msgs in one go?
User Status
Sort or Order post with combination of both (Replies + Activity)
Dynamically update available user field values during a profile fill in
Can I create a dashboard for a specific group inside the community?
Error during upgrading from Beta 3.1.x to latest
Must have plugins and components for Discourse?
Full IP access log
Available settings for global rate limits and throttling
How can I use GUI to access the postgresql db in docker
Data Explorer query for topics N+ days old, that are unsolved
Page Publishing
Tips for Exporting User Data
Identify private message interactions between users
View tag changes
Types of community & their characteristics
Discourse Chatbot :robot:
Run Data Explorer queries with the Discourse API
2023: The Year in Review
"Ensure ad-blockers are disabled and try reloading the page." when enabling Data Explorer
Exploring Discourse Data Explorer on my Sandbox
Order/Filter searched topics by latest update to First Post
Discourse Automation
API Filter users by emails, including secondary emails
How do I clear user warnings?
Exclude certain categories from the Trust Levels
Topic Ratings Plugin
Forum Data
Is it possible to view all staff notices?
Discourse Retort
Advice on archiving a site
Cleaning up uploads and purging uploads from S3
Content Audit : Report to pull Categories, Topics and Replies
Exporting all Forum Posts for Manual Upload into External LLMs?
discourse容器部署方式下,如何在外部连接到数据库,例如使用DBeaver连接
I'm attempting to merge user accounts
获取昨日点赞或者浏览量,前10的帖子
Populate Data Explorer params with URL params
AI sentiment and emotion analysis reports
Bulk Export of Raw Post Sources with Markup
Bundling more popular plugins with Discourse core
Setting up automated admin notice alerts
Listing event invitees with email addresses
More charting options for Data Explorer
Topics list filter feature
Migrate a phpBB3 forum to Discourse
Using Parameters in Data Explorer Queries
How to find how long a user has viewed a topic/who has posted new topics/country of users
Error trying to edit a post with an image in (NginX Proxy Manager?)
Restrict moderator access to only the stats panel on the admin dashboard?
How does auto-close topics work?
Poll: Export poll results in CSV for quiz creator?
Query to find out who marked the solution as solved
Possible to run a report for most posts within community?
Add an Admin subtab for Inactive users
Questions regarding Discourse features
How to query an email list of users that are not actived
Advice on a support forum
Shopify Integration
How do I see Facebook signups?
Creating and managing polls
Poll: Export poll results in CSV for quiz creator?
Discourse disk space limits per user?
Sorting all users by total posts?
SQL: The most N used words per user (speak their language!)
User Summary - Most Liked By user attributions are incorrect
Maximum Number of Search Results?
Get only top level posts in topic via discourse API
How to get all the deleted posts for a specific topic
Stats reports on a per-category basis?
Data analytics by complex networks and text mining
Error thrown when importing a query in Data Explorer
Zero search results searching private messages for specific keyword
A way to see full list of users granted with a certain badge?
Who messaged the most?
Who messaged the most?
How to open hyperlinks in a new tab
Run report of digest Unsubscribes
Need log the who downloaded attachments
Poll problem - exact vote numbers needed
Telegram Notifications Plugin (discourse-telegram-notifications)
Get last :heart: via API
Is it possible to keep the votes history of a poll?
How do I check a badge's status midway to it being awarded?
What plugins do you use - and why?
Export list of users based on date range
How to get all posts a user interacted with?
How can I email all recently active users?
Raw Function limited to 100

你好! :slight_smile:

我在这个帖子中询问了如何复制搜索查询中所有主题的链接。我被引导到这里。所以,我问了我们的论坛的管理员,我们是否安装了这个插件,我们确实安装了。但是,我们不知道如何使用它来使用这个插件将搜索查询中的所有链接复制到CSV文件中。有人以前做过这件事吗?也许可以指引我们一下? :sweat_smile:

请注意,我是论坛的普通用户,我没有管理权限。但是,我正在将此信息转达给有权限的网站管理员,他可以为我做这件事。 :slight_smile:

提前感谢!

你好 Preston!

Data Explorer 插件允许你创建 SQL 查询。

你想创建一个新的查询来列出你正在寻找的主题。

然后,当你运行查询时,你会看到一个 CSV 按钮,用于将结果导出到 CSV 文件。

希望这有帮助!

如果你在创建查询方面需要更多帮助,请告诉我们!

3 个赞

谢谢!我会转达的 :拥抱:

3 个帖子已拆分为新主题:如何解决 Data Explorer 10,000 条结果限制问题?

您好,我有一个关于这个很棒插件的功能请求。

我使用数据探索器创建的一些报告,如果我能在仪表板报告(/admin/reports)页面列出它们,对我的团队将非常有帮助。

是否可以为每个数据探索器查询添加一个选项,使其能在报告页面列出?谢谢。

例如:

  • 报告页面列出此自定义查询
3 个赞

感谢这个功能!

我正在探索如何编写自定义指标。我们正在将 Discourse 与 Workadvent.re(一个基于 2D 头像的 A/V 协作工具)一起使用。
我正在那里运行一个自定义脚本,通过 webhook 将活动记录到 Google 表格中。为了将所有内容集中在我们核心工具(Discourse)中,将这些数据打印到 Discourse 中将非常棒……
有什么建议吗?!

1 个赞

我真的很希望有一个查询生成器可以帮助编写 SQL。我的 SQL 很老旧而且生疏,手动编写 SQL 容易出错且耗时。如果有一种更简单的方法就好了!

2 个赞

您好 @davidgs,欢迎来到 Meta :wave: :slight_smile:

您尝试过使用像 ChatGPT 这样的 LLM 吗?它对 Discourse 有相当的理解,并且在我需要制作数据探索器查询时也相当可靠。

我经常这样写提示:“编写一个 Discourse 数据探索器查询,从 a,b,c 中返回 x,y,z,其中…” 然后就能得到相当不错的结果。

在本页的右上角,您可能还会看到一个小机器人图标,如下所示。
image

如果那里有的话,您也可以尝试集成在 Meta 中的 AI Helper Bot。

2 个赞

我们大多数人都看不到它。但总有 ask.discourse.com

2 个赞

是的,我不记得这是否仍然只是一个3级信任才能使用的功能。你推荐的ask.discourse.com网站是个好主意。

作为参考示例,我将“写一个 discourse 数据探索查询,返回所有说过“software”一词的用户列表”输入到ask.discourse.com的文本输入栏中,得到了以下查询:

SELECT 
    p.user_id, 
    u.username,
    COUNT(p.id) AS post_count
FROM 
    posts p
JOIN 
    users u ON u.id = p.user_id
WHERE 
    p.raw ILIKE '%software%'
GROUP BY 
    p.user_id, u.username
ORDER BY 
    post_count DESC;

这相当合理。我还可以证明它能处理比这复杂得多的查询。

2 个赞

我安装 Discourse 和 Data Explorer 的最新更新大约两个小时后,数据浏览器的导出数据不再有效。数据本身创建正常,但无法再导出。

点击 JSON 或 CSV 按钮只会闪烁一下,然后什么也没发生。大约两周前它还能正常工作。

在网络浏览器控制台中,我看到以下错误:
CSV:

Uncaught TypeError: this.args.query is undefined
    _downloadResult query-result.js:310
    downloadResultCsv query-result.js:287
    _triggerAction d-button.gjs:160
    Ember 12
    _triggerAction d-button.gjs:157
    click d-button.gjs:106

JSON:

Uncaught TypeError: this.args.query is undefined
    _downloadResult query-result.js:310
    downloadResultJson query-result.js:283
    _triggerAction d-button.gjs:160
    Ember 12
    _triggerAction d-button.gjs:157
    click d-button.gjs:106
1 个赞

感谢您的 bug 报告,@GuidoD

我今天早些时候合并了一个针对此问题的修复程序,请尝试更新并确认它是否对您有效。 :slight_smile:

2 个赞

感谢您快速修复。
我可以确认它又可以正常工作了。

1 个赞

少量数据导出到 JSON 和 CSV 都可以正常工作。但对于大量数据,CSV 导出工作正常,但 JSON 导出在 nginx 中会导致 502 错误网关(可能是因为 30 秒后超时,而 JSON 文件创建时间超过 30 秒)。

有没有简单的方法可以增强 nginx 的超时值?

如果我缩短查询的时间范围,csv 文件为 12.9 MB,json 文件为 645 MB。总的 csv 文件为 13.5 MB,只比这个大一点点,但 json 文件由于 nginx 错误而未创建。

或者,JSON 文件创建是否由于某些奇怪的数据而出错?JSON 文件创建会生成日志文件吗?

JSON 查询默认比 CSV 查询运行更高的外部 LIMIT。在查询内部添加自定义分页以确保其按时完成。

1 个赞

是否可以从数据浏览器执行 UPDATE 语句?

我正在尝试对某个表进行批量更新,但出现此错误:

PG::FeatureNotSupported: ERROR:  WITH 查询“query”不包含 RETURNING 子句
第 29 行: ) SELECT * FROM query

不,Data Explorer 仅执行只读事务。(如果您更新查询以包含 RETURNING 子句,您将收到只读事务错误。)

如果您是自托管用户,请使用“启动器输入”指南之一,例如

如果您已经设计好 UPDATE,那么您可以 psql discourse 而不是 rails c

如果您使用的是托管服务,请联系支持部门让他们执行更改。

1 个赞

感谢您的回复。说得通。我们使用的是托管服务,所以我会联系他们的支持团队。

如果我与版主组共享 SQL 查询,该组中的用户如何从他们的帐户运行查询?他们看不到数据浏览器插件。