Search for labels with prefix on a confluence page
Asked by Suresh Venkat:

Hi,

I would like to search for pages with labels which are prefix with say characters OTB or otb. For example if page 1 has label OTB_First and page 2 has label otb_second, my search (CQL or Confluence search) for any page starting with OTB or otb, should give me 2 pages or even if give me labels - should give me OTB_First , otb_second

Any ideas?

Thanks,

Suresh


Answers:
author: Nicolai Sibler
body: Hi [@Suresh Venkat](/t5/user/viewprofilepage/user-id/3731638) ,

if you have the possibility to run a query against the database, here's your SQL:

```
SELECT c.title,s.spacename,l.name as label
FROM content c
JOIN spaces s ON s.spaceid = c.spaceid
JOIN content_label cl ON cl.contentid = c.contentid
JOIN label l ON l.labelid = cl.labelid
WHERE l.name LIKE 'otb%'
AND c.contenttype = 'PAGE'
AND c.prevver IS NULL;
```

comments: author: Suresh Venkat
body: [@Nicolai Sibler](/t5/user/viewprofilepage/user-id/2649119) : We are looking at how to display it on a page. Is there anyway, we can fire this query from a confluence page - may be via an REST/Macro. Do you know? Thanks for the query though.


author: Nicolai Sibler
body: Complementary to what Kishan said, you might also have a [look at some Plugins](https://marketplace.atlassian.com/search?product=confluence&query=sql). (I have no experience with any of them tbh.)


author: Kishan Sharma
body: Hi [@Suresh Venkat](/t5/user/viewprofilepage/user-id/3731638) If you have access to the database, the easiest way to find this information is through the database. (Make sure you have a backup of your database before performing any SQL query.) Refer [this link](https://confluence.atlassian.com/confkb/how-to-query-the-database-to-find-pages-using-a-specific-label-in-confluence-987144349.html) on a sample query which you can modify as per your needs.

comments: author: Suresh Venkat
body: [@Kishan Sharma](/t5/user/viewprofilepage/user-id/3398562) : As you can see, we are looking to search and display on a page via a Macro or CQL. Any help can be provided will be appreciated


author: Kishan Sharma
body: As Brant mentioned, wildcard search for labels is not possible through the user interface currently. Either, you can export the query output from the database, and attach it to the confluence page or [create a page](https://docs.atlassian.com/ConfluenceServer/rest/7.14.0/#api/content-createContent) using REST API and provide the exported output from the db query as an input (in json format) to the rest call.


author: Brant Schroeder
body: [@Suresh Venkat](/t5/user/viewprofilepage/user-id/3731638) There is not a wildcard search for labels available in Confluence or Jira. I was able to find an enhancement request for Jira but not for Confluence. I would suggest submitting one here. <https://jira.atlassian.com/secure/Dashboard.jspa>

comments: author: Suresh Venkat
body: [@Brant Schroeder](/t5/user/viewprofilepage/user-id/769100) : Thanks for the inputs. Can you please point us to the Enhancement that you have put in for Jira. We want to see, if it matches to our case.


author: Brant Schroeder
body: [@Suresh Venkat](/t5/user/viewprofilepage/user-id/3731638) The enhancement request I was able to find for Jira is here: <https://jira.atlassian.com/browse/JRASERVER-23038>


author: Suresh Venkat
body: Thanks a lot [@Brant Schroeder](/t5/user/viewprofilepage/user-id/769100) . I have submitted <https://jira.atlassian.com/browse/CONFSERVER-73979>


Tags: confluence-server

label

server