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 Mi Piace

Ciao! :slight_smile:

Quindi ho chiesto in questo thread come copiare i link di tutti gli argomenti in una query di ricerca. Sono stato indirizzato qui. Quindi, ho chiesto al manager di il nostro forum se avessimo questo plugin installato, cosa che abbiamo. Tuttavia, non sappiamo come usarlo per copiare tutti i link da una query di ricerca in un file CSV usando questo plugin. Qualcuno ha già fatto questa operazione e magari può indicarci la giusta direzione? :sweat_smile:

Nota che sono un utente regolare del forum, non ho poteri di staff. Tuttavia, sto riportando queste informazioni al gestore del sito che li ha e che può farlo per me. :slight_smile:

Grazie in anticipo!

Ciao Preston!

Il plugin Data Explorer ti permette di creare query SQL.

Vuoi crearne una nuova che elenchi gli argomenti che cerchi.

Quindi, quando esegui la query, vedrai un pulsante CSV per esportare il risultato in un file CSV.

Spero che questo aiuti!

Facci sapere se hai bisogno di ulteriore aiuto per creare la query!

3 Mi Piace

Grazie! Lo riferirò :abbracci:

3 post sono stati divisi in un nuovo argomento: Come aggirare il limite di 10.000 risultati di data explorer?

Ciao, ho una richiesta di funzionalitĂ  per questo ottimo plugin.

Alcuni dei report che creo utilizzando Data Explorer, sarebbero molto utili al mio team se potessi elencarli nella pagina Dashboard Reports (/admin/reports).

Sarebbe possibile aggiungere un’opzione a ciascuna query di Data Explorer per essere elencata nella pagina Reports? Grazie.

Ad esempio:

  • Elenca questa query personalizzata nella pagina Reports
3 Mi Piace

Grazie per questa funzionalitĂ !

Sto esplorando come potremmo scrivere metriche personalizzate. Stiamo utilizzando Discourse insieme a Workadventu.re (uno strumento di collaborazione A/V basato su avatar 2D).
Sto eseguendo uno script personalizzato lì per scrivere attività in un foglio Google tramite un webhook. Per avere tutte le cose centralizzate nel nostro strumento principale (Discourse), sarebbe fantastico avere questi dati stampati in Discourse…
Qualche consiglio?!

1 Mi Piace

Speravo davvero che ci fosse un generatore di query che aiutasse a scrivere SQL. Il mio SQL è vecchio e arrugginito e scriverlo a mano è soggetto a errori e richiede tempo. Sarebbe bello se ci fosse un modo piÚ semplice!

2 Mi Piace

Ciao @davidgs, benvenuto su Meta :wave: :slight_smile:

Hai provato a usare un LLM come ChatGPT? Ha una discreta comprensione di Discourse ed è stato abbastanza affidabile quando ho dovuto anche creare query per l’esplorazione dei dati.

Spesso scrivo i miei prompt come “Scrivi una query di esplorazione dati di Discourse che restituisca x,y,z da a,b,c dove…” e ottengo qualcosa di abbastanza ragionevole.

Nell’angolo in alto a destra di questa pagina potresti anche vedere una piccola icona di robot come quella qui sotto.
image

Se è così, potresti anche provare l’AI Helper Bot integrato con Meta.

2 Mi Piace

La maggior parte di noi non la vede. Ma c’è sempre ask.discourse.com

2 Mi Piace

SĂŹ, non ricordavo se questa fosse ancora solo una cosa di livello di fiducia 3 o meno. Buona idea per il sito ask.discourse.com.

Come esempio di riferimento, ho inserito scrivi una query di esplorazione dati di discourse che restituisca un elenco di tutti gli utenti che hanno detto la parola "software" nella barra di inserimento del testo di ask.discourse.com e ho ottenuto la seguente query:

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;

Abbastanza ragionevole. Posso anche garantire che esegue query significativamente piĂš complesse di questa.

2 Mi Piace

L’esportazione dei dati dall’esplora dati non funziona più con gli ultimi aggiornamenti di Discourse ed Esplora dati che ho installato circa due ore fa. I dati vengono creati correttamente ma non è più possibile esportarli.

Fare clic sui pulsanti JSON o CSV provoca solo un breve lampeggio e non succede nient’altro. Ha funzionato bene circa due settimane fa.

Nella console del browser web vedo il seguente errore:
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 Mi Piace

Grazie per la segnalazione del bug, @GuidoD!

Ho unito una correzione per questo problema in precedenza oggi, prova ad aggiornare e conferma che funziona per te. :slight_smile:

2 Mi Piace

grazie per la rapida soluzione.
Confermo che funziona di nuovo correttamente.

1 Mi Piace

per una piccola quantità di dati, l’esportazione in JSON e CSV funzionano correttamente. Ma per una maggiore quantità di dati, l’esportazione CSV funziona bene ma l’esportazione JSON genera un errore nginx 502 bad gateway (probabilmente a causa di un timeout dopo 30 secondi, poiché la creazione del file JSON richiede più di 30 secondi).
Esiste un modo semplice per aumentare il valore di timeout di nginx?

Se riduco l’intervallo di tempo della query, il file CSV è di 12,9 MB e il file JSON è di 645 MB. Il file CSV totale è di 13,5 MB, quindi solo un po’ più grande, ma il file JSON non viene creato a causa dell’errore nginx.

O forse la creazione del file JSON sta riscontrando un errore a causa di dati anomali. La creazione del file JSON crea un file di log?

Le query JSON vengono eseguite con un LIMIT esterno superiore per impostazione predefinita rispetto alle query CSV. Aggiungere la paginazione personalizzata all’interno della query per garantire il completamento in tempo.

1 Mi Piace

È possibile eseguire istruzioni UPDATE da Data Explorer?

Sto cercando di eseguire un aggiornamento massivo di una certa tabella, ma ottengo questo errore:

PG::FeatureNotSupported: ERROR:  WITH query "query" does not have a RETURNING clause
LINE 29:   ) SELECT * FROM query

No, Data Explorer esegue solo transazioni di sola lettura. (Se aggiornassi la tua query per includere una clausola RETURNING, otterresti un errore di transazione di sola lettura.)

Se stai auto-ospitando, utilizza una delle guide “launcher enter”, come

Se hai giĂ  progettato il tuo UPDATE, puoi usare psql discourse invece di rails c.

Se sei su un servizio ospitato, contatta il supporto per far eseguire la modifica.

1 Mi Piace

Grazie per la risposta. Ha senso. Utilizziamo un servizio ospitato, quindi contatterò il loro supporto.

Se condivido una query SQL con il gruppo dei moderatori, come possono gli utenti del gruppo dei moderatori eseguire la query dal proprio account? Non possono vedere il plugin Data Explorer.