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:

شكراً مقدماً!

مرحباً بريستون!

تسمح لك إضافة مستكشف البيانات بإنشاء استعلامات SQL.

تريد إنشاء استعلام جديد يسرد الموضوعات التي تبحث عنها.

بعد ذلك، عند تشغيل الاستعلام، سترى زر CSV لتصدير النتيجة إلى ملف CSV.

آمل أن يساعدك هذا!

أخبرنا إذا كنت بحاجة إلى مساعدة إضافية في إنشاء الاستعلام!

3 إعجابات

شكرا لك! سأمرر ذلك :عناق:

تم تقسيم 3 مشاركات إلى موضوع جديد: التحايل على حد الـ 10,000 نتيجة لمستكشف البيانات؟

مرحباً، لدي طلب ميزة لهذا المكون الإضافي الرائع.

ستكون بعض التقارير التي أنشئها باستخدام مستكشف البيانات مفيدة جدًا لفريقي إذا كان بإمكاني إدراجها في صفحة تقارير لوحة المعلومات (/admin/reports).

هل سيكون من الممكن إضافة خيار لكل استعلام في مستكشف البيانات ليتم إدراجه في صفحة التقارير؟ شكراً.

على سبيل المثال:

  • إدراج هذا الاستعلام المخصص في صفحة التقارير
3 إعجابات

شكراً على هذه الميزة!

أنا أستكشف كيف يمكننا كتابة مقاييس مخصصة. نحن نستخدم Discourse جنبًا إلى جنب مع Workadvent.re (أداة تعاون ثنائية الأبعاد قائمة على الصور الرمزية).
أقوم بتشغيل نص برمجي مخصص هناك لكتابة الأنشطة في ورقة Google عبر خطاف ويب. للحصول على كل الأشياء مركزية في أداتنا الأساسية (Discourse)، سيكون من الرائع طباعة هذه البيانات في Discourse…
أي نصائح؟!

إعجاب واحد (1)

كنت آمل حقًا أن يكون هناك مُنشئ استعلامات يساعد في كتابة SQL. لغة SQL لدي قديمة وصدئة، وكتابتها يدويًا عرضة للأخطاء وتستغرق وقتًا طويلاً. سيكون من الرائع لو كانت هناك طريقة أسهل!

إعجابَين (2)

مرحباً @davidgs، أهلاً بك في Meta :wave: :slight_smile:

هل جربت استخدام LLM مثل ChatGPT؟ لديه فهم معقول لـ Discourse وكان موثوقًا به إلى حد معقول عندما احتجت أيضًا إلى إجراء استعلامات مستكشف البيانات.

غالبًا ما أكتب مطالباتي مثل “اكتب استعلام مستكشف بيانات Discourse يُرجع x، y، z من a، b، c حيث …” وينتهي بي الأمر بشيء معقول جدًا.

في الجزء العلوي الأيمن من هذه الصفحة، قد ترى أيضًا أيقونة روبوت صغيرة مثل أدناه.
image

إذا كان الأمر كذلك، يمكنك أيضًا تجربة مساعد الذكاء الاصطناعي المدمج في Meta.

إعجابَين (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 ومستكشف البيانات التي قمت بتثبيتها قبل حوالي ساعتين. يتم إنشاء البيانات بشكل جيد ولكن لم يعد من الممكن تصديرها.

النقر على أزرار 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)

شكراً على تقرير الخطأ، @GuidoD!

لقد قمت بدمج إصلاح لهذه المشكلة في وقت سابق اليوم، يرجى محاولة التحديث وتأكيد أنه يعمل لديك. :slight_smile:

إعجابَين (2)

شكراً على الإصلاح السريع.
أؤكد أنه يعمل بشكل جيد مرة أخرى.

إعجاب واحد (1)

بالنسبة لكمية صغيرة من البيانات، يعمل كل من التصدير إلى JSON و CSV بشكل جيد. ولكن بالنسبة لكمية أكبر من البيانات، يعمل تصدير CSV بشكل جيد ولكن تصدير JSON يؤدي إلى خطأ 502 Bad Gateway في nginx (ربما بسبب انتهاء المهلة بعد 30 ثانية حيث يستغرق إنشاء ملف JSON وقتًا أطول من 30 ثانية).
هل هناك طريقة سهلة لزيادة قيمة انتهاء مهلة nginx؟

إذا قمت بتقليل الإطار الزمني للاستعلام، فإن ملف csv يبلغ حجمه 12.9 ميجابايت وملف json يبلغ حجمه 645 ميجابايت. يبلغ حجم ملف csv الإجمالي 13.5 ميجابايت، وهو أكبر قليلاً فقط، ولكن ملف json لا يتم إنشاؤه بسبب خطأ nginx.

أو ربما يفشل إنشاء ملف JSON بسبب بعض البيانات الغريبة. هل يقوم إنشاء ملف JSON بإنشاء ملف سجل؟

تُشغَّل استعلامات JSON بحدٍّ خارجي أعلى بشكل افتراضي مقارنةً باستعلامات CSV. أضف ترقيم صفحات مخصصًا داخل الاستعلام لضمان اكتماله في الوقت المناسب.

إعجاب واحد (1)

هل من الممكن تنفيذ عبارات UPDATE من مستكشف البيانات؟

أحاول إجراء تحديث جماعي لجدول معين، لكنني أحصل على هذا الخطأ:

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

لا، يقوم مستكشف البيانات بتنفيذ المعاملات للقراءة فقط. (إذا قمت بتحديث استعلامك ليشمل جملة RETURNING، فستحصل على خطأ في معاملة القراءة فقط.)

إذا كنت تستضيف بنفسك، فاستخدم أحد أدلة “launcher enter”، مثل

إذا كان لديك بالفعل تحديثك مصممًا، فيمكنك استخدام psql discourse بدلاً من rails c.

إذا كنت تستخدم خدمة مستضافة، فاتصل بالدعم ليقوموا بتنفيذ التغيير.

إعجاب واحد (1)

شكرًا على الرد. فهمت الأمر. نحن على خدمة مستضافة، لذلك سأتواصل مع دعمهم بعد ذلك.

إذا شاركت استعلام SQL مع مجموعة المشرفين، فكيف يمكن للمستخدمين في مجموعة المشرفين تشغيل الاستعلام من حساباتهم؟ لا يمكنهم رؤية المكون الإضافي لمستكشف البيانات.