If you create a rule with the input mode set to “Advanced”, then the “After days” and the “Term based conditions” fields are replaced with an “Advanced query conditions” field, which is mandatory:
When writing queries using Keyword Query Language (KQL) you can use SharePoint’s built-in managed properties or your own defined managed properties to search for specific documents using Relationship operators.
Using date properties in a query
When you want to set a condition that is based on the value of any of the documents’ date fields (e.g. the built in columns “Modified” or “Created” or any custom fields like “Document date” or “Review date”), then you can use this format to write a condition:
[ManagedPropertyName][RelationshipOperator]{[variable]-X}, where:
- [ManagedPropertyName] could be:
- “Created” (for creation date)
- “LastModifiedTime” (for last modified date)
- “RefinableDate01” for a custom column such as “Document date”, whose crawled property has been mapped to an available managed property, RefinableString01.
- [RelationshipOperator], when it comes to date values normally is one of these:
- < (before a specific date)
- <= (before or on a specific date)
- > (after a specific date)
- >= (after or on a specific date)
- [Variable] is typically “today” but any of these could also be used:
- yesterday
- “this week”
- “this month”
- “last month”
- “this year”
- “last year”
- X is the number of days
- The maximum number of days you can add in this date-formula is 3650 (10 years).
So to create a rule that runs on all documents that are created a year ago or earlier, write this condition:
created<={today-365}
This date formula cannot be used in MetaShare’s or SharePoint’s standard search.
Other document properties that can be used in a query
Here are examples of some regular managed properties that could be used in advanced queries:
- Path
- Is used to find documents whose full URL starts with a specific path.
- Examples:
- Path:”https://contoso.sharepoint.com/sites/XYZ”
- Documents in the specific site.
- Path:”https://contoso.sharepoint.com/sites/XYZ*”
- Documents in sites whose URL start with the specific string.
- -Path:”https://contoso-my.sharepoint.com”
- No documents that reside in OneDrive.
- Path:”https://contoso.sharepoint.com/sites/XYZ/Shared documents”
- Documents in the specific library.
- Path:”https://contoso.sharepoint.com/sites/XYZ”
- ParentLink
- Is used to find documents whose path contains a certain string, e.g. the part of the document’s URL that contains the site’s or the folder’s name. If you are searching for documents in a certain folder, it will also show the documents that reside in the folder’s subfolders.
- Examples:
- ParentLink:”XYZ”
- Documents whose part of their paths contains the specific string.
- ParentLink:”XYZ*”
- Documents whose part of their paths begins with the specific string.
- -ParentLink:”XYZ”
- No documents whose part of their paths contains the specific string.
- ParentLink:”XYZ”
- SiteTitle
- Is used to find documents whose site names contains a certain string.
- Examples:
- SiteTitle:”XYZ”
- Documents in sites whose site name contains the specific string.
- -SiteTitle:”XYZ”
- No documents in sites whose site name contains the specific string.
- SiteTitle:”XYZ”
- Examples:
- Is used to find documents whose site names contains a certain string.
- CreatedBy
- Is used to find documents that are created by a specific user.
- Examples:
- CreatedBy=”John Smith”
- Documents created by “John Smith”.
- -CreatedBy=”John Smith”
- No documents created by “John Smith”.
- CreatedBy=”John Smith”
- ModifiedBy
- Is used to find documents that are last modified by a specific user.
- Examples:
- ModifiedBy=”John Smith”
- Documents last modified by “John Smith”.
- -ModifiedBy=”John Smith”
- No documents last modified by “John Smith”.
- ModifiedBy=”John Smith”
- Filename
- Is used to find documents whose file names equals or consists of a certain string.
- Examples:
- filename:test
- Documents whose filenames consists of “test”.
- filename=”test.docx”
- Documents whose filenames equals “test.docx”.
- filename:test
- FileType
- Is used to find documents whose file suffix is of a certain type.
- Examples:
- FileType:pdf
- Documents of filetype PDF.
- -FileType:pdf
- No documents of filetype PDF.
- FileType:pdf
- SPContentType
- Is used to find documents of a certain content type.
- Example:
- SPContentType=document
- Documents whose content type is the default “Document”.
- SPContentType=document
- ContentTypeId
- Is used to find documents whose content type has a specific ID.
- Example:
- ContentTypeId:”0x010100C8B208CF6653E646B70692BAF6E96976*”
- Documents whose content type inherits from the specific content type ID.
- ContentTypeId:”0x010100C8B208CF6653E646B70692BAF6E96976*”
- UIVersionStringOWSTEXT
- Is used to find documents whose latest version number is a specific number.
- Examples:
- UIVersionStringOWSTEXT=”1.0″
- All documents that have been published to version 1.0.
- UIVersionStringOWSTEXT:(“1.0” OR “2.0” OR “3.0” OR “4.0”)
- All documents that have been published to version 1.0, 2.0, 3.0 or 4.0.
- UIVersionStringOWSTEXT=”0.*”
- All documents that never have been published to a major version.
- UIVersionStringOWSTEXT=”1.0″
How to combine the properties to a full query
These different relationship operators can be combined with Boolean operators to form a more definite condition. Here is an examples of an advanced query condition that queries for all documents in sites whose site url starts with “project” or “support” and that are created at least a year ago, except for pdf-files:
Path:("https://contoso.sharepoint.com/sites/project*” OR "https://contoso.sharepoint.com/sites/support*”) created<{today-365} -FileType:pdf
This is an example of a rule that queries for all documents that are stored in a folder named “archive” except if the documents are stored in sites with archive in their site names or if they are stored in the users’ OneDrives:
ParentLink:"archive" -sitename:"archive" -Path:"https://contoso-my.sharepoint.com"
A recommendation, when creating advanced rules, is to always test the query before Publishing the rule. This is done by clicking on the “Test rule” button beneath the “Advanced query condition” field. The files that are listed in the report window are all documents that the MetaShare Orbit app has permission to see (which are all files in your Microsoft 365 tenant).
Note
- Advanced rules with advanced query conditions are very powerful and therefore you should always test your rules before publishing them.
- You do not need to add these KQL parameters in advanced queries, as MetaShare Orbit automatically adds them when executing the rules:
- ContentTypeId:0x0101*
- This is to ensure that Orbit just manages documents as all documents inherit from the base content type whose ID is 0x0101. All document content types will therefore always start with a 0x0101, hence the wildcard at the end.
- -FileType:aspx
- To exclude web pages.
- -ParentLink:/SiteAssets/
- To exclude any files that are located in the standard SiteAssets library.
- ContentTypeId:0x0101*
- MetaShare Orbit will also automatically exclude all sites that in MetaShare Orbit’s settings page are defined as excluded sites and all sites that at any point of time have been defined as destination libraries (even if they are removed in Orbit).