Using KQL in Microsoft Search

Using the Keyword Query Language (KQL) in your queries in Microsoft Search, you can restrict your search to only pull back the specific results you want. This is a very powerful way to limit search results when the available filters don’t meet your requirements and the bonus is that KQL works across all of the search verticals.

KQL enables you to build advanced queries for searching providing you the ability to very specifically target you search should the need arise.

Free text queries

First thing to realise is that the way you use free text in a query, including a KQL query, matters and can be used to improve the focus of your search. Next is that the * wildcard operator is available where you want to expand the scope of words covered by your search:

  • federated search – returns results that contain either of the words in no particular order
  • “federated search” – returns results that match the exact phrase
  • federa* search – Introduces the wildcard match operator *. This search returns results with the word search and any word that starts with ‘federa‘ e.g federal, federation, federated etc.
  • federated sea* – this search returns results with the word federated and any word that starts with ‘sea‘ e.g seas, seal, search etc.
  • *rated – suffix matching is not supported so this search will return results for the word rated it will not return results matching the words federated, prorated, perforated etc.

Property restrictions

Using KQL, you can construct queries that use property restrictions to narrow the focus of the query to match only results based on a specified property condition. 

  • author:”John Smith” – returns content items authored by John Smith
  • filetype:docx – returns Microsoft Word documents
  • filename:budget.xlsx – returns content items with the filename budget.xlsx
  • filename:bud* – returns content items where the filename contains words starting with bud e.g. ‘budget.xlsx’ or ‘buddy plan.docx’ or ‘Pursuit Budget and Staffing.pdf’
  • title:“federated sea*”– wildcard operator only supported at the end of the phrase
  • contentclass:STS_Web – returns SharePoint sites. You can find a complete list here​​​​​​​

The properties available for restricting your search may vary when searching verticals based on external connections such as ITConnect, HRConnect, DXC Internet and Salesforce, as the external connection will be configured to provide queriable properties relevant to that source. If you would like more information about the queriable properties for a particular external connection please make the request via the Enterprise Search community in Yaammer.

​​​​​​​Boolean and Proximity operators

To enable you to broaden or focus your search KQL provides a set of boolean (AND, OR, NOT) and proximity operators (NEAR, ONEAR). 

OperatorDescription
ANDReturns search results that include all of the free text expressions, or property restrictions specified with the AND. You must specify a valid free text expression and/or a valid property restriction both preceding and following the AND operator.
NOTReturns search results that do not include the specified free text expressions or property restrictions. You must specify a valid free text expression and/or a valid property restriction following the NOT operator. This is functionally the same as using the minus (“–”) character.
ORReturns search results that include one or more of the specified free text expressions or property restrictions. You must specify a valid free text expression and/or a valid property restriction both preceding and following the OR operator.
ALL(x y z)Returns results that match all terms contained in the parenthesis
ANY(x y z)Returns search results that include at least one of the terms in the parenthesis


You can use proximity operators to match the results where the search terms you provide are near to each other in the content.

  • NEAR will look for the terms in proximity regardless of the order of the terms, as long as no more than eight terms separate them.
  • ONEAR enforces that they are near AND in the order you specify them, as long as no more than eight terms separate them.
  • Proximity of the terms covers from the first term followed by up to eight other terms, and then an instance of the second term.
  • Proximity can only be used with free text, it cannot be applied to properties.
  • For both NEAR and ONEAR you can also specify the proximity from 0 to 8. For example, to search for the terms enterprise and search, in that order, in proximity and with no more than 1 term between them you would use   enterprise ONEAR(1) search​​​​​​​

Multiple property restrictions

  • author:”John Smith” author:”Jane Smith” – this will return results where the author is John Smith or Jane Smith
  • author:”John Smith” OR author:”Jane Smith” – this is the same as the preceding line
  • “federated search” AND author:”Jane Smith” – this will only return results where both the phrase federated search exists and the author is Jane Smith

Grouping property restrictions is possible using parenthesis () to group them:

  • author:”John Smith” author:”Jane Smith can be written author:(“John Smith” “Jane Smith”) 
  • (feder* NEAR search) NOT federated  – returns results where words starting with feder are found in proximity to the word search but excludes the word federated e.g.  “Federal Oil uses search” and “federation of indexes will enable search” would match but “search within DXC is federated” will not match.

Date/Time support

  • LastModifiedTime=today – Matches would include items modified today
  • LastModifiedTime=“this year” – Matches would include items modified this year. Criteria also includes “yesterday”, “this week”, “this month”, “last month” and “last year”
  • LastModifiedTime>=2019-01-01 AND LastModifiedTime<=2019-04-26 – Matches would include items from January 1st of 2019 until April 26th of April, 2019.
  • federated AND contentclass:STS_Web – returns SharePoint sites where the word federated appears in the site title, site name, site description. 2019

Want to learn more? Here are some additional resources to help…

Leave a comment