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

%3CLINGO-SUB%20id%3D%22lingo-sub-1612657%22%20slang%3D%22en-US%22%3EKQL%20syntax%20to%20query%20for%20all%20documents%2C%20files%20and%20list%20items%20in%20auto%20applied%20retention%20label%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1612657%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%3CBR%20%2F%3E%3CBR%20%2F%3EI'm%20trying%20to%20come%20up%20with%20the%20best%20filter%20for%20auto%20retention%20to%20be%20set%20with.%3CBR%20%2F%3EWhat%20will%20be%20the%20best%20way%20to%20auto%20apply%20retention%20on%20a%20SharePoint%20site%20to%20%3CSTRONG%3Enot%3C%2FSTRONG%3E%20include%20non%20end%20user%20working%20data%3F%20stuff%20like%20site%20assets%20or%20style%20library%20files.%3CBR%20%2F%3E%3CBR%20%2F%3EI'm%20trying%20to%20just%20target%20documents%2C%20files%20within%20working%20libraries%20and%20list%20items%20which%20may%20include%20attachments.%3CBR%20%2F%3E%3CBR%20%2F%3EI've%20tried%20this%20syntax%3A%3CBR%20%2F%3EIsDocument%3A1%20AND%20(ContentType%3A'Document'%20OR%20ContentType%3A'Item')%20AND%20-FileType%3Aaspx%3CBR%20%2F%3E%3CBR%20%2F%3Eobviously%20this%20does%20not%20return%20list%20item%20since%20it's%20failing%20on%20the%20IsDocument%20clause.%3CBR%20%2F%3EHowever%2C%20if%20I%20omit%20the%20IsDocument%20part%20and%20have%20it%20like%20so%3A%3CBR%20%2F%3E(ContentType%3A'Document'%20OR%20ContentType%3A'Item')%20AND%20-FileType%3Aaspx%3CBR%20%2F%3E%3CBR%20%2F%3EThis%20returns%20%22non%20working%22%20files%20as%20well%20such%20as%20items%20in%20site%20assets%20or%20style%20library%20which%20can%20be%20different%20file%20types.%20This%20is%20happening%20because%20the%20contenttype%20is%20set%20to%20document%20by%20default%20on%20these%20backend%20libraries.%3CBR%20%2F%3E%3CBR%20%2F%3EWhich%20brings%20me%20back%20to%2C%20how%20can%20I%20set%20auto%20applied%20retention%20to%20library%20documents%2C%20library%20files%2C%20list%20items.%20Do%20I%20have%20to%20create%20two%20separate%20labels%20in%20order%20to%20achieve%20my%20requirement%3F%3CBR%20%2F%3E%3CBR%20%2F%3EThanks%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Visitor

Hello,

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?

Thanks 

1 Reply

@Chris215 

 

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.

and(FileType:or("docx","xlsx","pptx"),site:equals("https://mytenant.sharepoint.com/sites/sitecollection/subsite/Some%20Templates"))