Discourse Data Explorer

:discourse2: Summary Discourse Data Explorer allows you to make SQL queries against your live database, allowing for up-to-the-minute stats reporting.
:open_book: Install Guide This plugin is bundled with Discourse core. There is no need to install the plugin separately.

:information_source: If you’re looking for examples or support for any custom queries, you can find lots of topics in our Data & reporting category under the sql-query tag. If there’s not one to suit your particular needs, please feel free to create a new topic to ask the community for some help. :memo: Query Help

:discourse2: Hosted by us? This plugin is available on our Business and Enterprise plans. Data Explorer | Discourse - Civilized Discussion

After installing the plugin, head to /admin/plugins .

de1

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 buttons to get started.

Default queries

On a fresh install, the data explorer now ships with several queries that can help you draw insights from your forum’s activity. Open any query and click Run to try it out.

Here's what the stock queries look like.

Note: Default queries are picked up from this file: discourse-data-explorer/lib/discourse_data_explorer/queries.rb at main · 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.

Writing queries

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.

Automatically running queries

While you can always run a query by clicking the Run button, you can save time when loading a query by adding the run parameter to the URL.

For example: /admin/plugins/explorer/queries/123?run

When this parameter is added to the URL, the query will run as soon as you load the page, so you don’t need to click the Run button to see the results. This is especially helpful for queries you run frequently, allowing you to bookmark them or add them to your sidebar with the run parameter included for a one-click report.

Importing 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 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 :heart:

Searching for queries

If you’ve accumulated too many awesome queries, no problem! The search bar can help you filter through titles and descriptions.

Allow non-staff groups to run queries

You can add specific groups (including moderators) to a query to grant them access to it:

After saving, you can find it from the Groups page for that particular group on the Reports tab:

Click any query to open it and then the Run button to see the results. You can also bookmark group reports by clicking the Bookmark button.

Sharing queries with predefined parameters

If you have included user-defined parameters in your query, you can share a link to the query and include the parameters in the URL so they will be pre-filled when the page loads.

You must include parameters in the URL in this format params={"parameter_name":"value"}. Separate multiple parameters with commas. For example:

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

Couple with the run parameter mentioned above, you can share a report with predefined parameters that runs automatically when loaded.

Result limits and exporting queries

With large queries, you may notice that there is a limit on the number of rows that the Data Explorer will display. By default, the limit is set to 1000 rows. This is to prevent excessively large queries from slowing down or disrupting the performance of your Discourse instance.

If you want to bypass this limit, you have a few of options:

  1. Pagination: You can paginate your results. Instead of trying to return all results at once, you can write your query to return a specific range of results. You can then adjust this range to view different sections of your data. This won’t increase the limit, but it will allow you to view all your data in sections.
  2. Increase the limit: If you have access to the Discourse server and are comfortable making changes to Discourse settings, you can increase the limit. However, this should be done with caution. Increasing the limit can put a lot of load on your server if you’re not careful, especially if multiple users are running large queries at the same time.
  3. Download the Results: You also have the option to download the query results instead of viewing them directly in Discourse by clicking either the JSON or CSV button after running the query. Data downloaded from a query in JSON or CSV format will have a much higher results limit of 10,000 rows. For programmatic purposes, you want want to opt for the Json format, or if you’d like to work on the data in a spreadsheet application, the CSV format might be more convenient.

It’s generally a good idea to try and write more efficient queries, or to filter your data so that you’re only retrieving what you need, rather than trying to bypass the limit.

You can also export the SQL query itself in .JSON format by clicking the Export button. Queries that are exported using this method can then be imported into other Discourse sites, or used with third party applications.

Query plan

The “Include query plan” checkbox can be used for better understanding and optimizing your SQL queries.

When you check this box and run a query, Discourse will display the sequence of operations used to access data in the Discourse database. This can include operations like scans, joins, sorts, and other database actions. By examining the query plan, you can see exactly how the database is executing your query.

The Data Explorer tutorial series

We also have a dedicated sql-tutorial series about the Data Explorer! If you’re interested in learning more about writing SQL queries in Discourse, we highly recommend reading through the topics in this series:

Last edited by @hugh 2025-09-03T00:45:12Z

Last checked by @hugh 2025-09-03T00:45:21Z

Check documentPerform check on document:
「いいね!」 119

こんにちは! :slight_smile:

こちらのスレッドで、検索クエリ内のすべてのトピックのリンクをコピーする方法を尋ねました。こちらに誘導されました。そこで、私たちのフォーラムのマネージャーに、このプラグインがインストールされているか尋ねたところ、インストールされているとのことでした。しかし、このプラグインを使用して、検索クエリからすべてのリンクをCSVファイルにコピーする方法がわかりません。どなたかこの操作を行った経験のある方はいらっしゃいますか?もしよろしければ、ご教示いただけますでしょうか? :sweat_smile:

なお、私はフォーラムのレギュラーユーザーであり、スタッフ権限はありません。しかし、サイトマネージャーにこの情報を伝えており、彼は私に代わって実行できます。 :slight_smile:

よろしくお願いします!

こんにちは、プレストンさん!

Data Explorer プラグインを使用すると、SQL クエリを作成できます。

探しているトピックを一覧表示する新しいクエリを作成したいと考えています。

次に、クエリを実行すると、結果を CSV ファイルにエクスポートするための CSV ボタンが表示されます。

お役に立てば幸いです!

クエリの作成に追加のヘルプが必要な場合は、お知らせください!

「いいね!」 3

ありがとうございます。お伝えします :hugs:

3件の投稿が新しいトピックに分割されました:データエクスプローラーの10,000件の結果制限を回避する方法?

こんにちは。この素晴らしいプラグインに機能リクエストがあります。

Data Explorer を使用して作成するレポートの一部は、ダッシュボードのレポート (/admin/reports) ページに一覧表示できれば、チームにとって非常に役立ちます。

Data Explorer の各クエリに、レポートページに一覧表示するオプションを追加することは可能でしょうか?よろしくお願いします。

例:

  • このカスタムクエリを レポート ページに一覧表示する
「いいね!」 3

この機能ありがとうございます!

カスタムメトリクスを記述する方法を検討しています。DiscourseとWorkadventu.re(2DアバターベースのA/Vコラボレーションツール)を併用しています。
現在、カスタムスクリプトを実行して、Webhook経由でGoogleスプレッドシートにアクティビティを記録しています。すべてのものを中心的なツール(Discourse)に集約するために、これらのデータをDiscourseに表示できると素晴らしいのですが…

何かヒントはありますか?!

「いいね!」 1

SQLの作成に役立つクエリビルダーがあればと強く思っていました。私のSQLは古く錆びついており、手作業で作成するのは間違いやすく時間がかかります。もっと簡単な方法があればいいのですが!

「いいね!」 2

こんにちは、@davidgsさん、Metaへようこそ :wave: :slight_smile:

ChatGPTのようなLLMを試しましたか? Discourseを reasonably 理解しており、私もデータエクスプローラーのクエリを作成する必要があった際にはかなり信頼できました。

プロンプトはよく「Discourseのデータエクスプローラークエリで、a,b,cからx,y,zを返すものを…という条件で書いてください」のように記述しており、かなり妥当なものが得られています。

このページの右上にも、以下のような小さなロボットのアイコンが見えるかもしれません。
image

もしそうであれば、Metaに統合されているAIヘルパーボットも試すことができます。

「いいね!」 2

ほとんどのユーザーには表示されていません。しかし、ask.discourse.com は常に利用可能です。

「いいね!」 2

ええ、これがまだ信頼レベル3限定のものだったかどうか思い出せませんでした。ask.discourse.comサイトへの言及は良いですね。

参考例として、「'software’という言葉を言ったすべてのユーザーのリストを返すDiscourseデータエクスプローラークエリを記述してください」を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 ボタンをクリックしても、短いフラッシュが表示されるだけで何も起こりません。2週間前は正常に機能していました。

Web ブラウザのコンソールに次のエラーが表示されます。
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

ご報告ありがとうございます、@GuidoD さん!

本日、この問題に対する修正をマージしました。アップデートして、正常に動作するか確認していただけますでしょうか。:slight_smile:

「いいね!」 2

迅速な修正ありがとうございます。
正常に動作することを確認しました。

「いいね!」 1

少量のデータであれば、JSONとCSVのエクスポートはどちらも正常に機能しています。しかし、大量のデータの場合、CSVのエクスポートは正常に機能しますが、JSONのエクスポートはnginxで502 Bad Gatewayが発生します(おそらくJSONファイルの作成に30秒以上かかるため、30秒後のタイムアウトが原因だと思われます)。
nginxのタイムアウト値を簡単に増やす方法はありますか?

クエリの期間を短縮すると、CSVファイルは12.9MB、JSONファイルは645MBになります。CSVファイル全体のサイズは13.5MBなので、それほど大きくありませんが、JSONファイルはnginxのエラーにより作成されません。

あるいは、JSONファイルの作成が奇妙なデータのためにエラーになっている可能性もありますか?JSONファイルの作成はログファイルを作成しますか?

JSONクエリはデフォルトでCSVクエリよりも高い外部LIMITで実行されます。クエリ内でカスタムページネーションを追加して、時間内に完了するようにしてください。

「いいね!」 1

Data Explorer から UPDATE ステートメントを実行することは可能ですか?

特定のテーブルの一括更新を試みていますが、このエラーが発生します。

PG::FeatureNotSupported: ERROR:  WITHクエリ「query」にはRETURNING句がありません
LINE 29:   ) SELECT * FROM query

いいえ、Data Explorer は読み取り専用トランザクションのみを実行します。(クエリに RETURNING 句を追加して更新した場合、読み取り専用トランザクションのエラーが発生します。)

セルフホストしている場合は、「launcher enter」ガイドのいずれかを使用してください。

すでに UPDATE を設計している場合は、rails c の代わりに psql discourse を使用できます。

ホストサービスを利用している場合は、サポートに連絡して変更を実行してもらってください。

「いいね!」 1

返信ありがとうございます。理にかなっています。私たちはホスティングされたサービスを利用しているので、彼らのサポートに連絡します。

SQLクエリをモデレーターグループと共有した場合、モデレーターグループのユーザーは自分のアカウントからクエリを実行するにはどうすればよいですか?彼らはData Explorerプラグインを見ることができません。