Skip to main content
< All Articles

How to only search for contents of the files in SharePoint Online

Posted on May 23, 2023
SharePoint

When you often execute a search in SharePoint Online, you only intend to find the documents that match the specific keyword you typed in. However, because SharePoint search is pretty powerful, it returns many more results than what you need. In today’s article, I will share a quick tip/trick on only searching for the files’ contents in SharePoint Online.

How does SharePoint Online search work?

The mighty SharePoint search is pretty powerful. When you type a keyword into a search box, say at the library level, it searches for that keyword in multiple locations. Here is where it searches for that keyword:

The problem with basic keyword search

So given the above, when you say, execute a search for the keyword “accounting,” it will return any results that match that keyword: file name, folder name, any metadata columns that match this keyword, and obviously and documents that contain that word inside of the documents.

only search for contents of the files in SharePoint Online

Likewise, if I execute a keyword search for my name (Gregory), it will return all the results that happen to have the keyword anywhere (file name, metadata, contents of the file). Moreover, since my name “Gregory” is associated with Modified or Created system columns, it will return all the documents I ever created or modified in the library, giving me much more than what I was looking for.

Searchfilecontentssharepointonline2

The use case for document contents search

So a typical scenario could be that I only want to search the documents that contain the word “accounting” or “Greg.” I only need documents containing either of these words in the document’s body (i.e., Word, Excel, PDF, etc.). I do not need any other files that have those keywords in the file or folder name or metadata columns.

How to only search for contents of the files in SharePoint Online

So the trick to only search for contents of the files in SharePoint Online is pretty simple. We are going to rely on the Keyword Query Language (KQL). All you need to do is type in the following text in the search box:

body:keyword

For example, in my case, I will type in body:accounting

The result would be the documents that only contain those keywords and not any other documents!

only search for contents of the files in SharePoint Online

only search for contents of the files in SharePoint Online

Simple, yet powerful!

Where you can utilize the content search in SharePoint Online

You can use body:keyword search at any level in SharePoint Online. In the example above, I showed you how to use that trick at the library level, but you can also execute that search in other “SharePoint Search Boxes” in SharePoint:

About Me

I’m Greg Zelfond, a U.S. based SharePoint consultant, and I provide affordable out-of-the-box SharePoint consulting, training, and configuration assistance to small and medium-sized businesses all over the world.

Need help?