Search attachements by file extensions using CQL

Hi there my fellow devs :laughing:,

I am trying to search attachements by file extensions by CQL with the server REST API.
Until now I have tried following query type=attachment and title~"*.bpmn" to find all attachments with the .bpmn file extension.

Unfortunately this doesn’t work and only 2 out of 12 files in the test case are found. I really don’t know why this is so.

Do you have a clue? Thank you for your help!

Hello @LukasGobelet

The file’s extension is excluded from the file’s title. You need to use sitesearch~"file.extension:bpmn"

Refer to this page for a more detailed explanation of searching for attached files by their extension using the Canned Search for Confluence add-in app.


Thank you very much for this information, Sir.
It’s much appreciated :slightly_smiling_face:

I will try this!

@sunnyape Do you also know how the CQL would need to be in order to find attachements with different file extensions? E.g. all files with these extensions .jpg;.jpeg;.png?

1 Like

Alright, an OR is sufficient:
type=attachment and (title~"Li*") and (sitesearch~"file.extension:jpg" OR sitesearch~"file.extension:jpeg" OR sitesearch~"file.extension:png")

1 Like

Okay a new problem has arisen :sweat:. We develop a plugin simultaneously for Confluence Server and Confluence Cloud and the problem ist that the CQL with sitesearch doesn’t work in the cloud. :disappointed_relieved:

It looks like all the articles about searching for attachments by their extension / content type using sitesearch are written for Confluence Server / Datacentre. There doesn’t seem to be an equivalent for Confluence Cloud yet

So, I think you have two options:

  1. Install Canned Search for Confluence. It’s free and if its sitesearch~(file.extension:xyz) function works to solve this specific problem for Confluence Cloud, then that’s great.
  2. If not, just search for all the attachments, in batches, then filter the resulting JSON responses to isolate the particular ones that have the extensions at the end of the title field.

Personally, I’d also raise a Confluence Cloud feature request, as it’s a bit silly that the JSON object title contains the file extension, but you can’t find it via the contains operator in a CQL search.

1 Like

@sunnyape Thank you again for your help and the detailed explanation of the options.

Yeah, we have already implemented the second option. We have some problems that the search doesn’t always return all the results. In order to improve the search i wanted to include the file extension in the CQL. It was also the case that we haven’t made the next requests, which is fixed now.
I think I will leave it by that.

Thank you for your help :smiley: