KQL syntax to query for all documents, files and list items in auto applied retention label

Occasional Visitor


I'm trying to come up with the best filter for auto retention to be set with.
What will be the best way to auto apply retention on a SharePoint site to not include non end user working data? stuff like site assets or style library files.

I'm trying to just target documents, files within working libraries and list items which may include attachments.

I've tried this syntax:
IsDocument:1 AND (ContentType:'Document' OR ContentType:'Item') AND -FileType:aspx

obviously this does not return list item since it's failing on the IsDocument clause.
However, if I omit the IsDocument part and have it like so:
(ContentType:'Document' OR ContentType:'Item') AND -FileType:aspx

This returns "non working" files as well such as items in site assets or style library which can be different file types. This is happening because the contenttype is set to document by default on these backend libraries.

Which brings me back to, how can I set auto applied retention to library documents, library files, list items. Do I have to create two separate labels in order to achieve my requirement?


1 Reply



I had the same problem. I have solved it with (FileType:docx OR FileType:pptx OR ...) and also just targeting a folder (site:"https://mytenant.sharepoint.com/sites/mysite/SomeFolder") is a handy solution in some cases.


Tip for anyone googling this. When using PNP search web parts, and you want a Refiner setting, you need to use FQL.