Useful CQL statements to search what you need in Confluence

CQL or Confluence Query Language is a powerful search language. It is a secret trick that only advanced Confluence users will know. 

Unlike its famous sibling JQL which is used in Jira advanced searching, CQL is not as well known and not well documented.

 

Here are some useful CQLs that you can use to search what exactly you need.

 

How to find a page by title within a specified space

space = SPACEKEY AND title ~ "meeting minutes"

This one helps to filter out a lot of noise especially when a lot of other pages also contains the same keyword

 

How to find an attachment by name

space = SPACEKEY AND type = Attachment AND title ~ "screenshot"

 

How to find a pdf attachment which the content contains a keyword (Confluence)

type = attachment AND title ~ "pdf" AND text ~ "confluence"

 

How to find a page containing a Confluence macro (e.g. CQL Navigation Macro)

type = Page AND macro = cqlnavigation

 

How to find a blog post that was created within the last month

space = SPACEKEY AND type = blogpost AND created > startOfMonth("-1M") AND created < startOfMonth()

 

How to find the comments you wrote over the past 1 week sorted by date posted

type = comment AND creator = currentUser() AND created > startOfDay("-1w") order by created desc

 

You can execute the CQL search by pasting it in the browser address bar in the format 

https://<confluence-base-url>/dosearchsite.action?cql=<CQL in the example below>.

Alternatively, it is possible to encode the CQL inside macros by Confluence apps such as Canned Search for Confluence so that users can use them directly without having to memorise the CQL syntax.

You can also find the guide to advance searching with CQL here

 

If you have any useful CQL statements to share, you are welcome to add on the list.

 

11 comments

Ulrich Kuhnhardt _IzymesCo_
Atlassian Partner
August 8, 2021

Thanks for sharing. Your article makes CQL more approachable.

Like # people like this
Roman
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!
March 3, 2023

How can we build a cql query to just search for a  term? E.g.: I  want to search for  "cold wallet"

but cql = "term ='cold wallet' " gives a 400 bad request invalid cql query

Robert Klohr
Contributor
April 24, 2023

@Roman The syntax you need is:

https://your-domain.atlassian.net/wiki/rest/api/content/search?cql=text~"cold wallet"
Like Hua Soon SIM _Akeles_ likes this
Aron Gombas _Midori_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 25, 2023

@Hua Soon SIM _Akeles_ It is a great article illustrated with practical examples!

I agree CQL is very useful, although on Cloud, in our experience consistency is a problem. It may return contents it should not and not return contents it should after a mass-update on contents, and it may take a few minutes until reaches the state of consistency. In contrary, Jira and JQL work much better in this sense.

The other problem is that CQL is not available natively in the UI for some reason?! There are some macros, luckily, that support CQL and can be used to build report pages in Confluence

Like Hua Soon SIM _Akeles_ likes this
Levente Szabo _Midori_
Atlassian Partner
August 14, 2023

Thanks, @Hua Soon SIM _Akeles_ for this list!

In a similar fashion, the team behind Better Content Archiving for Confluence Cloud published a broad list of CQL examples to help users define what they are searching for, like:

  • Confluence page status
  • Contents without an owner
  • Expired content
  • Contents without an expiration date

If you give Better Content Archiving a try for your automated content lifecycle needs (page status, notifications, and archiving/deletion) I'm sure you'll find it useful!

Like # people like this
Jenna Ingersoll
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!
August 17, 2023

I'm trying to return everything expect the latest blog post. Any ideas on the CQL? 

Hua Soon SIM _Akeles_
Atlassian Partner
January 25, 2024

Hi  @Jenna Ingersoll ,

Can you elaborate what do you mean to return everything expect the latest blog post?

Tauhid Smith
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!
December 6, 2024

Is there any operator or something that will return results on an "any" basis, instead of "all"? For example...

space = SPACEKEY AND title ~ "meeting minutes"

 Is there any query that would take this search for title and return all individual results for both "meeting" and "minutes" rather than results for "meeting minutes"?

Hua Soon SIM _Akeles_
Atlassian Partner
December 8, 2024

When you search

space = SPACEKEY AND title ~ "meeting minutes"

It is equivalent to 

space = SPACEKEY AND (title ~ "meeting" OR title ~ "minutes")

 

CC Lab January 7, 2025

how to write query for the  to get all updated documents  , we have only lastmodified tag not lastupdated  how can we handle this case  

Hua Soon SIM _Akeles_
Atlassian Partner
January 12, 2025

Based on https://developer.atlassian.com/server/confluence/advanced-searching-using-cql/#field-reference

lastmodified will search for content that was last modified on, before, or after a particular date (or date range).

 

There is no lastupdated field. Can you elaborate what you are expecting from the lastupdated field?

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events