Set up search query field mapping
When you need exact phrase matching in GraphQL search queries on the Experience Edge (Preview) schema, use the SearchQueryFieldMapping feature to map tokenized fields to non-tokenized computed fields. This translation happens internally in the query-building code, before queries are sent to the Solr search provider.
By default, text fields in the Solr index are tokenized, a process that splits text into individual terms using whitespace and punctuation. For example, "New Site" becomes "new" and "site" separately. While this works for general text searches, it breaks exact phrase matching: a search query for _name == "Site" with the EQ operator behaves as CONTAINS, returning multiple results.
To resolve this, you can create a non-tokenized field (such as _customName) using a field type like lowercaseString that preserves the complete value as a single token, then map the original _name field to it during search operations. This enables exact matching while maintaining backward compatibility.
Make sure you have:
-
Access to your SitecoreAI environment.
-
Familiarity with SitecoreAI configuration files and deployment processes.
Configure search query field mapping
The following example demonstrates how to set up search query field mapping by mapping the _name field to a _customName computed field. For complete instructions on creating computed fields, see Creating a computed index field.
To configure the SearchQueryFieldMapping feature:
-
Create a new computed index field
Create a new computed field using the existing implementation
Sitecore.Services.GraphQL.EdgeSchema.ComputedFields.CustomNameComputedField.Add new fields to the
AddComputedIndexFieldnode in thecontentSearchsection of your configuration file.This example creates the
_customNamefield using thelowercaseStringtype: -
Map the search field name to the computed field
To set up field mapping, add a field name mapping model to the
setFieldMappingnode. This model will be processed by theSearchQueryFieldMappingServicewhen mapping a search query field.In the
fieldMappingModel, map the_namefield to the_customNamefield: -
Include patches and deploy to Sitecore
Commit your configuration patches from steps 1 and 2 to your project and deploy your SitecoreAI environment.
-
Rebuild the index
After deployment, rebuild the search index after making all the changes. After the index rebuild completes, the field mapping is active and ready to use.
Use the search query field mapping in queries
After configuration, for the Edge (Preview) schema, when you use the original field name (_name) in your GraphQL search queries, the mapping automatically redirects the query to use the non-tokenized field (_customName) internally in the Solr index. This means you continue using the original field name in your code while benefiting from exact matching behavior.
Example: Exact Match Query
When you use the EQ operator on the _name field, the search returns items matching the exact value. This query searches for "Sitecore Experience" and requests the id and name fields for each matching item:
Without the field mapping, this same query would return multiple results containing any of the tokenized terms. With the mapping to _customName, it returns only items where the name exactly matches "Sitecore Experience".
Example: Contains Query
The CONTAINS operator returns items that contain the search term, regardless of field mapping. This query searches for items containing "Sitecore" and requests the id and name fields:
When configuring field mappings, consider the following:
-
The original field name (
_name) remains usable in queries after mapping is configured. -
Field mapping applies to the Preview endpoint only.
-
Multiple fields can be mapped to different non-tokenized versions.
-
Custom field names must be consistent between computed field definition and field mapping configuration.