# Search attachements by file extensions using CQL

**URL:** <https://community.developer.atlassian.com/t/search-attachements-by-file-extensions-using-cql/52951>\
**Category:** Confluence Server\
**Tags:** confluence-server, attachment, cql, rest-api\
**Created:** [October 18, 2021, 11:29am UTC](https://community.developer.atlassian.com/t/search-attachements-by-file-extensions-using-cql/52951 "2021-10-18T11:29:31Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![LukasGobelet](https://avatars.discourse-cdn.com/v4/letter/l/65b543/32.png) [@LukasGobelet](https://community.developer.atlassian.com/u/LukasGobelet)\
**Post date:** [October 18, 2021, 11:29am UTC](https://community.developer.atlassian.com/t/search-attachements-by-file-extensions-using-cql/52951/1 "2021-10-18T11:29:31Z")

</div>

Hi there my fellow devs 😆,

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!

---

<div class="post-metadata">

**Author:** ![anon96974232](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@anon96974232](https://community.developer.atlassian.com/u/anon96974232)\
**Post date:** [October 18, 2021, 8:55pm UTC](https://community.developer.atlassian.com/t/search-attachements-by-file-extensions-using-cql/52951/2 "2021-10-18T20:55:16Z")

</div>

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](https://akeles.jira.com/wiki/spaces/CQL/pages/1136492604/How+to+limit+search+to+a+file+type+in+Confluence) for a more detailed explanation of searching for attached files by their extension using the _Canned Search for Confluence_ add-in app.

---

<div class="post-metadata">

**Author:** ![LukasGobelet](https://avatars.discourse-cdn.com/v4/letter/l/65b543/32.png) [@LukasGobelet](https://community.developer.atlassian.com/u/LukasGobelet)\
**Post date:** [October 22, 2021, 7:54am UTC](https://community.developer.atlassian.com/t/search-attachements-by-file-extensions-using-cql/52951/3 "2021-10-22T07:54:48Z")

</div>

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

I will try this!

---

<div class="post-metadata">

**Author:** ![LukasGobelet](https://avatars.discourse-cdn.com/v4/letter/l/65b543/32.png) [@LukasGobelet](https://community.developer.atlassian.com/u/LukasGobelet)\
**Post date:** [October 22, 2021, 8:33am UTC](https://community.developer.atlassian.com/t/search-attachements-by-file-extensions-using-cql/52951/4 "2021-10-22T08:33:58Z")

</div>

@anon96974232 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`?

---

<div class="post-metadata">

**Author:** ![LukasGobelet](https://avatars.discourse-cdn.com/v4/letter/l/65b543/32.png) [@LukasGobelet](https://community.developer.atlassian.com/u/LukasGobelet)\
**Post date:** [October 22, 2021, 8:51am UTC](https://community.developer.atlassian.com/t/search-attachements-by-file-extensions-using-cql/52951/5 "2021-10-22T08:51:40Z")

</div>

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")`

---

<div class="post-metadata">

**Author:** ![LukasGobelet](https://avatars.discourse-cdn.com/v4/letter/l/65b543/32.png) [@LukasGobelet](https://community.developer.atlassian.com/u/LukasGobelet)\
**Post date:** [October 22, 2021, 9:53am UTC](https://community.developer.atlassian.com/t/search-attachements-by-file-extensions-using-cql/52951/6 "2021-10-22T09:53:27Z")

</div>

Okay a new problem has arisen 😓. 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. 😥

---

<div class="post-metadata">

**Author:** ![anon96974232](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@anon96974232](https://community.developer.atlassian.com/u/anon96974232)\
**Post date:** [October 22, 2021, 11:05am UTC](https://community.developer.atlassian.com/t/search-attachements-by-file-extensions-using-cql/52951/7 "2021-10-22T11:05:59Z")

</div>

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](https://marketplace.atlassian.com/apps/1217056/canned-search-for-confluence?tab=installation&hosting=cloud). 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.

---

<div class="post-metadata">

**Author:** ![LukasGobelet](https://avatars.discourse-cdn.com/v4/letter/l/65b543/32.png) [@LukasGobelet](https://community.developer.atlassian.com/u/LukasGobelet)\
**Post date:** [October 22, 2021, 11:37am UTC](https://community.developer.atlassian.com/t/search-attachements-by-file-extensions-using-cql/52951/8 "2021-10-22T11:37:48Z")

</div>

@anon96974232 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 😃

---

<div class="post-metadata">

**Author:** ![MarkusWeigelt](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/markusweigelt/32/48548_2.png) [@MarkusWeigelt](https://community.developer.atlassian.com/u/MarkusWeigelt)\
**Post date:** [July 4, 2023, 4:52pm UTC](https://community.developer.atlassian.com/t/search-attachements-by-file-extensions-using-cql/52951/9 "2023-07-04T16:52:55Z")

</div>

> [@anon96974232](#):
>
> 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.

Do you have a link for this Confluence Cloud feature request?

---

<div class="post-metadata">

**Author:** ![anon96974232](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@anon96974232](https://community.developer.atlassian.com/u/anon96974232)\
**Post date:** [July 4, 2023, 7:12pm UTC](https://community.developer.atlassian.com/t/search-attachements-by-file-extensions-using-cql/52951/10 "2023-07-04T19:12:33Z")

</div>

> [@MarkusWeigelt](#):
>
> Do you have a link for this Confluence Cloud feature request?

It was up to the OP who raised the question to raise that request. Why not just just search through the [Confluence Cloud feature requests](https://www.google.com/search?client=firefox-b-d&q=Confluence+Cloud+feature+request) yourself to see what’s there.

---

<div class="post-metadata">

**Author:** ![MarkusWeigelt](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/markusweigelt/32/48548_2.png) [@MarkusWeigelt](https://community.developer.atlassian.com/u/MarkusWeigelt)\
**Post date:** [July 5, 2023, 1:27pm UTC](https://community.developer.atlassian.com/t/search-attachements-by-file-extensions-using-cql/52951/11 "2023-07-05T13:27:12Z")

</div>

> It was up to the OP who raised the question to raise that request. Why not just just search through the [Confluence Cloud feature requests](https://www.google.com/search?client=firefox-b-d&q=Confluence+Cloud+feature+request) yourself to see what’s there.

Within the atlassian systems it is not easy to find the right system and then the right ticket. I had already looked but did not find a suitable ticket.

---

<div class="post-metadata">

**Author:** ![anon96974232](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@anon96974232](https://community.developer.atlassian.com/u/anon96974232)\
**Post date:** [July 5, 2023, 10:20pm UTC](https://community.developer.atlassian.com/t/search-attachements-by-file-extensions-using-cql/52951/12 "2023-07-05T22:20:14Z")

</div>

It sounds like the feature request hasn’t been created. The proverbial ball is now in your court 🙂 to raise that request yourself and see what traction it gets.
