---
title: Sitecore Commerce – Add new field to Solr Index
description: When an index rebuild is invoked, sitecore XC indexes the properties of the catalog entity by default. These indexed fields are added to web & master indexes. To add a custom field to the index, we need to map the custom field to a field type & create a custom field handler. To register the […]
---

[Aperture Labs Insights ](https://www.aperturelabs.net/insights)

# [Sitecore Commerce – Add new field to Solr Index](https://www.aperturelabs.net/insights/blog/sitecore-commerce-add-new-field-to-solr-index)

 Written by [Sai Sumanth Mokkapati](https://www.aperturelabs.net/insights/author/sai-sumanth-mokkapati) | Jul 8, 2021

When an index rebuild is invoked, sitecore XC indexes the properties of the catalog entity by default. These indexed fields are added to web & master indexes. To add a custom field to the index, we need to map the custom field to a field type & create a custom field handler. To register the new custom field, we need to add an entry in the fields with appropriate type & add it to the search policy set. In this case, “PlugIn.Search.Solr.PolicySet-1.0.0.json”.

{   
   "$type" : "Sitecore.Commerce.Core.PolicySet, Sitecore.Commerce.Core" ,   
   "Id" : "Entity-PolicySet-SolrSearchPolicySet" ,   
   "Version" : 1 ,   
   "IsPersisted" : false ,   
   "Name" : "SolrSearchPolicySet" ,   
   "Policies" : {   
     "$type" : "System.Collections.Generic.List`1[[Sitecore.Commerce.Core.Policy, Sitecore.Commerce.Core]], mscorlib" ,   
     "$values" : [   
       {   
         "$type" : "Sitecore.Commerce.Plugin.Search.ItemIndexablePolicy, Sitecore.Commerce.Plugin.Search" ,   
         "IndexName" : "sitecore_web_index" ,   
         "FieldTypeMappers" : [   
           {   
             "TypeName" : "string" ,   
             "Type" : "System.String" ,   
             "NameFormat" : "{0}_s" ,   
             "CultureFormat" : "_{1}"   
           }   
         ] ,   
         "Fields" : [   
           {   
             "$type" : "Sitecore.Commerce.Plugin.Search.Solr.SolrIndexFieldConfiguration, Sitecore.Commerce.Plugin.Search.Solr" ,   
             "Name" : "CustomField" ,   
             "Type" : "System.String" ,   
             "TypeHint" : "string" ,   
             "Handler" : {   
               "$type" : "Custom.Sitecore.Commerce.Plugin.InRiverConnector.IndexFieldHandlers.CustomFieldIndexFieldHandler,  
                Custom.Sitecore.Commerce.Plugin.InRiverConnector"   
             }   
           }   
         ]   
       }   
     ]   
   }   
}

We need to add a custom field handler to compose a value for the custom field that needs to be indexed. To create a custom field index handler, we need to create a class that inherits from the “Sitecore.Commerce.Plugin.Search.AbstractIndexFieldHandler class”, and implement the ComposeValue method.

public class CustomFieldHandler : AbstractIndexFieldHandler   
{   
     public override object ComposeValue ( object source, ConcurrentDictionary < string, object > context )   
     {   
     if (context == null || source == null )   
     {   
         return null ;   
     }   
     return "Sample custom field handler value" ;   
     }   
}

We need to bootstrap the commerce engine environment to apply the changes. After this we need to restart the commerce engineer & rebuild the indexes.

[View full post](https://www.aperturelabs.net/insights/blog/sitecore-commerce-add-new-field-to-solr-index)

```json
{
  "@context" : "http://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Sai Sumanth Mokkapati"
  },
  "dateModified" : "2021-12-18T21:05:36.634Z",
  "datePublished" : "2021-07-08T00:41:56Z",
  "headline" : "Sitecore Commerce – Add new field to Solr Index",
  "image" : {
    "@type" : "ImageObject",
    "height" : 60,
    "url" : "/hs/hsstatic/content_shared_assets/static-1.4092/img/default-amp-logo.png",
    "width" : 60
  },
  "mainEntityOfPage" : "https://www.aperturelabs.net/insights/blog/sitecore-commerce-add-new-field-to-solr-index",
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "height" : 60,
      "url" : "/hs/hsstatic/content_shared_assets/static-1.4092/img/default-amp-logo.png",
      "width" : 60
    },
    "name" : "Aperture Labs Insights"
  }
}
```