Search for pages without label
Asked by Fabian_Holz:

Hi,

I have a set of pages, labelled as "active" or "inactive". It's important to me, that all pages have one of those labels.

As it might be that I forget to label a new page, I need to find unlabelled pages in my space (without checking each page one by one).

Unfortunately I was not able to find a way to search for unlabelled pages. All the solutions I found are very old and it seems, that those functions are not included in Confluence anymore.

Any ideas?

Regards

Fabian


Answers:
author: Diego
body: Hello [@Fabian_Holz](/t5/user/viewprofilepage/user-id/3939289) !

As I understand, you need to search for all pages within a specific Confluence Space and those pages should not contain a specific list of labels.

++*There is a native way for us to get those results*++ . It involves ++*Confluence Query Language (CQL)*++ and ++*Representational State Transfer Application Programming Interface (REST API)*++.

Here you can check our documentation:
> * ++***[\[Confluence Cloud Developer\] Advanced searching using CQL](https://developer.atlassian.com/cloud/confluence/advanced-searching-using-cql/)***++
> * ++***[\[Confluence Cloud Developer\] CQL Fields](https://developer.atlassian.com/cloud/confluence/cql-fields/)***++
> * ++***[\[Confluence Cloud Developer\] REST API](https://developer.atlassian.com/cloud/confluence/rest/)***++

Now, here is how we can get the desired content:
> 1. *Go to your Confluence site*
> 2. *Go to your desired space*
> 3. *Take note of the Space Key for that specific space*
> 4. *Use the following query: [https://yoursite.atlassian.net/wiki/rest/api/search?cql=label?NOT?IN("yourlabel","yourlabel2")?AND?type="page"?AND?space=YOURSPACEKEY](https://yoursite.atlassian.net/wiki/rest/api/search?cql=label?NOT?IN(%22yourlabel%22,%22yourlabel2%22)?AND?type=%22page%22?AND?space=YOURSPACEKEY)*
> 5. *The results should give you all the pages that do not contain the labels*

A little explanation of the query above.
> 1. The ++*["https://yoursite.atlassian.net/wiki"](https://yoursite.atlassian.net/wiki)*++ is your Confluence Site URL. You must replace the ++*"yoursite" part with your site name*++.
> 2. The "++*/rest/api/search*++" part tells Confluence you are asking for a REST call for a search
> 3. The "++*?cql=label?NOT?IN("yourlabel","yourlabel2")?AND?type="page"?AND?space=YOURSPACEKEY*++" part is the actual query. You must replace "yourlabel", "yourlabel2", and "YOURSPACEKEY" with your desired labels and space key.
> 4. Each "?" character is used to symbolize where a white space would be placed
> 5. The type="page" is what assures that the results will contain only pages and no blog posts, for example.

You can get your Space Key under Space Settings:
> ![Screen Shot 2020-05-27 at 12.26.23.png](https://community.atlassian.com/t5/image/serverpage/image-id/96642i099DBF2E11154FF1/image-dimensions/324x237?v=v2 "Screen Shot 2020-05-27 at 12.26.23.png")

Let me know if there is anything else I could assist you with!

comments: author: Fabian_Holz
body: Thank you :)


author: Diego
body: Glad to know the query helped you! Let me know if there is anything else we could help you with.


author: Suresh Venkat
body: Hello [@Fabian_Holz](/t5/user/viewprofilepage/user-id/3939289) / [@Diego](/t5/user/viewprofilepage/user-id/1188952)

I tried building the query like this *[https://yoursite.atlassian.net/wiki/rest/api/search?cql=label?NOT?IN("yourlabel","yourlabel2")?AND?type="page"?AND?space=YOURSPACEKEY](https://yoursite.atlassian.net/wiki/rest/api/search?cql=label?NOT?IN(%22yourlabel%22,%22yourlabel2%22)?AND?type=%22page%22?AND?space=YOURSPACEKEY)*

*Please clarify should it be like*

*[https://yoursite.atlassian.net/wiki/rest/api/search cql=label NOT IN("yourlabel","yourlabel2") AND type="page" AND space=YOURSPACEKEY](https://yoursite.atlassian.net/wiki/rest/api/search?cql=label?NOT?IN(%22yourlabel%22,%22yourlabel2%22)?AND?type=%22page%22?AND?space=YOURSPACEKEY)*

*where you have to replace ? with a space as above.*


author: Kevin Meehan
body: Hi there,

Apologies for resurrecting an older post...

I can't seem to get this query to work as OP requested: to return all pages within a Space that don't have a label.

What does ("yourlabel", "yourlabel2") in the query signify? The labels to be excluded from the result?

So I would have to declare all labels in use within that query to effectively display the pages that don't have any? Is that the gist of it? And if I forgot a particular label, then those pages would also be included?

I am just looking for any solution that can provide this result, ideally a macro, but I will settle for a script or advanced query I can save and run periodically...  

Thanks


author: Jawann
body: There is a request here to add a null value check to CQL: <https://jira.atlassian.com/browse/CONFCLOUD-76379>


Tags: cloud