CQL Query Syntax - Articles with no label

Zen Miles July 22, 2021

The CQL syntax appears to be a bit different in Confluence Cloud to the server version. Is there a way I can get all pages that have no labels?

3 answers

2 votes
Jessica
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 27, 2021

Hello Zen!

I hope you're well and safe!

I'm not familiar with the Server CQL version, but there could be some differences between those products, as they are different in how they work.

For Confluence Cloud, you should be able to search for pages without a label using the following through our REST API:

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

Please make sure to change the "yoursite" to your site name, "yourlabel" and "yourlabel2" with the labels on your pages and "YOURSPACEKEY" with the space key for the space where you want to search for pages without those labels, before running it. :)

  • You can find your space key by checking the URL, when accessing a space, should be after the /wiki/spaces, like on this example: https://sitename.atlassian.net/wiki/spaces/CBC/overview. <<<
    In this case, CBC is the space key.


I just did a quick test on a test instance by replacing the "yourlabel", "yourlabel2" for the only two labels in the space specified and it returned all the pages without a label there. :)

If you have any other labels being used in the space, you can also add them there, separating by a comma. 
If you don't, probably more pages will show up on the results and can have a label that was not specified in the "NOT IN".

For more additional information on how it works, you can check our documentation in our Developer Atlassian Community:


Other than that, we don't have a way to do it through the UI, but we have a feature request suggesting it to be implemented on our Content by Label macro:

Hope that helps, Zen!

Kindest Regards,
Jessica

CDougherty
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 19, 2024

Is there an easier way to do this with many labels?  My space has around 100 labels with new ones added every week or two so a query like that would be unwieldy and hard to maintain. 

0 votes
Hector Barquero
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 25, 2024

Not sure if still needed but this works in server 7.19 and in 8.5 LTS. Tried in my cloud instance, and it seemed to work too.

 

Find pages with labels

CQL query

type:page AND labelText:[a TO z]

 

The opposite, find pages with no labels

Use this one to confirm the first CQL results. The delta should equal the total site pages.

type:page NOT labelText:[a TO z]

 

0 votes
Janet Dixon August 20, 2021

Hi @Zen Miles   I was trying to do the same thing recently.  I'm NOT a developer, so I had to dig to find something that would be quick and easy for me.

I installed the add-on CQL Search, which is free:  https://marketplace.atlassian.com/apps/1213090/cql-search?hosting=cloud&tab=overview

I then used the CQL Query macro, checked boxes for the items I wanted to display, one of which was a labels column, and set the query for all pages in a specified space:

space=spacekey and type=page

I now have a page with a beautiful list of all the pages in the space with their respective labels, whether they have a label or not.  Now I can see all the pages that have no labels and what labels are applied to the other pages. 

You could modify the query to show you only those page that have no labels.

Zen Miles August 22, 2021

Thanks @Janet Dixon! I have actually already installed CQL Query which is what I am working in. Unfortunately we have a lot of articles in our knowledgebase, so the intention was to create a section that lists only unlabeled articles. Visually scanning a list for empty cells just doesn't cut it, I'm afraid.

It seems like CQL has a serious limitation in that it doesn't have a null or empty status. I have had to resort to using NOT IN LABEL "label-a" AND NOT IN LABEL "label-b" AND NOT IN LABEL "label-c", etc.

It is extremely annoying to have to do it this way, but if it's the only way that it will work, it has to do.

Janet Dixon August 23, 2021

@Zen MilesI was hoping to also have a list showing just the pages that have no labels.  I was struggling with this as well.  I'm surprised CQL doesn't have a null.  I will try your method.  Thanks for the tip.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
TAGS
AUG Leaders

Atlassian Community Events