Archive

Posts Tagged ‘query’

SharePoint 2013: Querying SharePoint log files

December 31, 2014 Leave a comment

Hi Friends,

While working as a SharePoint developer every one of us need to go to SharePoint log files to check exact nature and cause of error. SharePoint logs provide us vital information to resolve the issue. SharePoint provides us correlation id to get the details about the issue, but it is difficult some times to go and check the log files and manually find the error in log and get the cause, as log files are huge sometimes.

To resolve this we have some PowerShell cmdlets which we can use to search in log files. Some of them are Get-SPLogEvent and Merge-SPLogFile. We can discuss about them in more detail below.

1. Get-SPLogEvent-

We can use Get-SPLogEvent to query log files when either single server farm in place or we have knowledge on which server the error gets logged.So Get-SPLogEvent will query the logs in the same server where PowerShell command gets executed.Some of the samples below –

get-splogevent | ?{$_.Message -like "*Monitored*" -and $_.Correlation -eq "2713db9c-f21e-e0bc-3393-95ddcbf60bd0"} | select Area, Category, Level, EventID, Message | Format-List > C:\Log1.log

Above command will search with specified correlation id and get the content where message contains ‘Monitored’ word and dump the requested fields (Area, Category, Level, EventID, Message) in file Log1.log

get-splogevent | ?{$_.Correlation -eq "2713db9c-f21e-e0bc-3393-95ddcbf60bd0"} | select Area, Category, Level, EventID, Message | Format-List > C:\Log2.log

Above command will search with specified correlation id and dump the requested fields (Area, Category, Level, EventID, Message) in file Log2.log at specified path

You can use the above commands directly also on powershell to get the details directly instead of creating a file out of it, like

get-splogevent | ?{$_.Message -like "*user*" -and $_.Correlation -eq "2713db9c-f21e-e0bc-3393-95ddcbf60bd0" -and $_.Level -eq "Medium" -and $_.Category -eq "App Deployment"} | select Area, Category, Level, EventID, Message

Above command will search with specified correlation id and get the content where message contains ‘user’ word , Level is ‘Medium’ and Category equals ‘App Deployment’ and display the requested fields (Area, Category, Level, EventID, Message) on PowerShell window.

get-splogevent -StartTime "12/11/2014 10:00" -EndTime "12/12/2014 18:00"

Above command will search the logs with specified date range and display on PowerShell window.

2. Merge-SPLogFile-

We can use Merge-SPLogFile to query log files when we have a scenario where mult-server farm in place and we do not have idea where exactly the error get logged. i.e. timer service is running on four servers and the current timer request is served by Server1 then error get logged on server1. Some of the samples below –

Merge-SPLogFile -Path "C:\Log1.log" -Overwrite -Message "*Monitored*" – Correlation "2713db9c-f21e-e0bc-3393-95ddcbf60bd0"

Above command will search with specified correlation id and get the content where message contains ‘Monitored’ word and dump the details in file Log1.log

Merge-SPLogFile -Path "C:\Log2.log" -Overwrite -Message "*Monitored*" – Correlation "2713db9c-f21e-e0bc-3393-95ddcbf60bd0"

Above command will search with specified correlation id and dump the details in file Log2.log

Merge-SPLogFile -Path "C:\Log3.log" -Overwrite -StartTime "12/11/2014 10:00" - EndTime "12/12/2014 18:00"

Above command will search the logs with specified date range and dump the details in file Log3.log.
Hope this will reduce some of the debugging efforts.

“As the year comes to an end, don’t look back at yesterday’s disappointment. Look ahead to God’s promises yet to unfold.” ― Buky Ojelabi, comtemporary blogger
Happy new year 2015.

SharePoint 2013: Content Search web part query having query variables with multiple values

February 12, 2014 Leave a comment

Hi Friends,

While working with one of the SharePoint 2013 content search web part, I came across a query where query variables may return multiple values which causing my search query to fail, after struggling a lot I found a good TechNet article which solved my issue. Putting the solution here so that it will help someone from developer community.

For demo purpose I have created a Term set like following

TermSet

I have a user profile property (MyProfileProperty) which is bound to above term set. I have selected the profile property values for current logged in user.

User_Profile_Property

I have created a site column (MyTaxonomyColumn) which is bound to same term set and added that column in a list. After adding some entries in that list, I did a full crawl so that a managed property for the column will be created (owstaxIdMyTaxonomyColumn).

My requirement is to get all records from list having values from user profile property ‘MyProfileProperty’.

I have added a query like   {|owstaxIdMyTaxonomyColumn:{User.MyProfileProperty}}

Search_Query

This query gets transformed as following and worked for me as the above query syntax combines all the query variable values will be combined by using the bitwise OR operation.

Query_Transform

SharePoint 2013: Avoid default results in search result and content search web part with search box

August 9, 2013 10 comments

Hi Friends,

I faced one more issue recently related to SharePoint 2013 search, that I thought to share with you.

Scenario:

I have ‘Search Box’ web part and ‘Content Search’ web part on a page, search box is sending query keyword to content search web part to display results. Content search web part has couple of additional queries as following screen shot showing.

Search_Box_1

This query returning the results always and thus showing me the results before even started searching using search box web part, as shown in following image.

Search_Box_2

I wanted content search web part should show the results only when someone searches for it in search box, else results should not be displayed.

Solution:

I have modified the Content Search web part’s query like following, which given the expected results.

Search_Box_3

So after the query changes by default no results are displayed and I am getting results only when I searched using search box web part, as shown in following images.

Search_Box_4

Search_Box_5

The same changes will be applicable if you are using search results web part.

Hope this article will helpful for some of our friends, if any other good alternative for this found please let me also know about it.