In today’s post I am going to share about queries in Solr and how they can become helpful, specially during troubleshooting sessions.
For those who doesn’t know, Sitecore uses a search engine for two purposes in a standard installation:
Content search | this is the default search mechanism in Sitecore Experience Manager. The search engine indexes and finds content from the master , core or web databases. |
xConnect search | the Sitecore Experience Platform uses this search. The search engine indexes and finds contacts and interactions in the Experience Database. |
As a side note, Solr is used in other solutions as well, and, despite the fact this post is focused and using Sitecore values, please feel free to have a look at some queries in Solr.
A couple weeks ago I was troubleshooting an index issue in Sitecore, and one of the troubleshoot steps involved to perform queries directly in Solr.
After struggling a bit, I was able to execute the queries, so please find some examples in how to perform some queries in Solr
The begin
First you have to access Solr on its web interface, and click at Collection Selector then look for the index you want to query, in my case I want sitecore_master_index
Once you selected the index you want, there are some options available, choose Query
Query options
For the purpose of this post, the only field that is going to be modified to perform our queries is the q
Parameter | Description |
Request Handler | The way you are going to interact with solrconfig.xml, and the idea is to search, so let’s leave /select |
q | It is the query itself, where the sintax is built to show results |
fq | Applies a filter query to the search results |
sort | Sorts the response to a query in either ascending or descending order |
start | Specifies an offset (by default, 0) into the resposes at which Solr should begin displaying content |
rows | Controls how many rows of responses are displayed at a time (defaul value: 10) |
fl | Limits the information included in a query |
wt | Specifies the Response Writer to be used to format the query response |
indent off | Click this button to request that the Response Writer use indentation to make the responses more readable. |
debugQuery | Click this button to augment the query response with debugging information, including “explain info” for each document returned. This debugging information is intended to be intelligible to the administrator or programmer. |
dismax | Click this button to enable the Dismax query parser |
edismax | Click this button to enable the Extended query parser |
hl | Click this button to enable highlighting in the query response |
facet | Enables faceting, the arrangement of search results into categories based on indexed terms. |
spatial | Click to enable using location data for use in spatial or geospatial searches. |
spellcheck | Click this button to enable the Spellchecker, which provides inline query suggestions based on other, similar, terms |
First query
Let’s use the initial parameter *:* and press Execute Query to see some results
Query Syntax
Fields
Everything after the “response” output in bold are fields that can be used to compose our query
Values
Everything after “field”: either in green or red are the values that can be used to create our query
Query examples
The fields values are reflecting a Sitecore index but the concept behind the queries is the same, since it is executed in Solr.
Keyword match
If you observe the first arrow pointing to “numFound”, there are 49176 items found with the following query, and the parsedlanguage_s as expected showing english
Wildcard match
Using the query _uniqueid:*lang=en* means I want to find lang=en anywhere in the uniqueid field, and as you can see lang=en is in a random position of the value.
Multiple fields
The syntax has slighty changed to accept the AND in order to search for multiple fields but you are able to play around and reduce the results using additional fields
Guid search
In Sitecore the GUIDs are provided like this {207939C05-FCD8-4BCC-918E-09CE0440F4C1}, and in order to search them in Solr you have to change it as follows
As you can see the GUID search needs to happen in lower case and without the brackets, otherwise it won’t work
I hope you liked it, and I’ll see you on my next post
Deixe um comentário