Troubleshoot SharePoint 2013 search queries 101

There are some easy steps I follow every time I have to troubleshoot SharePoint 2013 search queries when I’m quite sure that I should get some result but the Search Result (or Content By Search, aka CBS) Web Part do not agree.

First of all, I have to admit, I’m not perfect and I know that very well so the first thing I double check is the query I wrote. I usually re-write the query from scratch using a tool other than out-of-the-box Query Builder, SharePoint 2013 Search Query Tool (v2.x).

I think everyone that works with SharePoint 2013 Search should know this tool and I will not write a review, but let me say that I’m a big fan of this software and I’m really thankful to its authors and contributors (check their names here). I love it because I can use it remotely, logged in as a different user or anonymously, I love it because it is easy to use, fast and rich of useful information.

Going back to my post, when I have to troubleshoot a search query I open Search Query Tool and type the query in the Query Text box using the KQL syntax. I usually start by adding one search term at a time until the query is complete. Search Query Tool does not “understand” SharePoint search  variables, so I have to “translate” it manually. Once finished, if I get some result, I go to the next step.

The “next step” is to check the query transformation done by SharePoint on the page render. Here comes the other tool I love, ULS Viewer. I wont say a word about it, since I’m sure that all you already know this software. So start it and take a look to the flow :)

When a page with a search results web part, including CBS, loads you can filter the ULS logs by “Name”, using the “contains” operator and the name o that page as a value. You’ll get a lot of results and between them something like this:

SearchExecutor::ExecuteQueries – Starting ExecuteQueryTask with correlation id 81262d21-e831-4ce1-8cf6-274bc5c45126

This is something really useful because it allow us to get the correlation id of the Query operations. Now we can add the correlation id as a filter on our ULS logs and take a look to the result. We could also add an addition filter, “Category contains Query”, to low down the logs number.

The resulting rows contain the complete query transformation “highlighting” (no, not literally…) how and when the query variables get translated in something different. We should also be able to get the number of search results.

  • QueryTemplateHelper: Query template ‘{SearchTerms} ContentType:CompanyEvent* Path:http://sample.com/en/*’ transformed to query text ‘ContentType:CompanyEvent* Path:http://sample.com/en/*’.
  • Microsoft.Office.Server.Search.Query.Pipeline.Processing.QueryRouterEvaluator : QueryRouterEvaluator: Received 15 RelevantResults results for query ContentType:CompanyEvent* Path:http://sample.com/en/* CorrelationId 81262d21-e831-4ce1-8cf6-274bc5c45126 ParentCorrelationId 81262d21-e831-4ce1-8cf6-274bc5c45126

This is something like the 101 of troubleshooting search query, but I found it really useful.

– Riccardo

Submit a Comment