SOLR field definitions for Sitecore analytics index

I am using SOLR as content search engine on most of my projects and recently figured out that segmentation rules for the List Manager don’t work.
Search logs showed errors about not found fields. This is because Sitecore ContentSearch needs to know field types so it can map them to respectife field endings. (fx. Guid field “contact.ContactId” needs to be converted into “contact.contactid_s”)

I ran through all analytycs index model and created a config file which maps each field to respective field type. This file can be named “Sitecore.ContentSearch.Solr.Index.Analytics.FieldDefinitions.config” and placed into “/App_Config/Include” folder.

So here is the file.

Sitecore.ContentSearch.Solr.Index.Analytics.FieldDefinitions.config

<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <contentSearch>
      <configuration>
        <indexes>
          <index id="sitecore_analytics_index">
            <configuration>
              <fieldMap>
                <fieldNames>
                  <field fieldName="key" returnType="text" />
                  <field fieldName="type" returnType="text" />
                  <field fieldName="isbucket_text" returnType="string" />

                  <!--Default Sitecore IndexableContact fields-->
                  <field fieldName="contact.Classification" returnType="int" />
                  <field fieldName="contact.VisitCount" returnType="int" />
                  <field fieldName="contact.Value" returnType="int" />
                  <field fieldName="contact.ContactId" returnType="guid" />
                  <field fieldName="contact.Identifier" returnType="text" />
                  <field fieldName="contact.Gender" returnType="text" />
                  <field fieldName="contact.PreferredEmail" returnType="text" />
                  <field fieldName="contact.Emails" returnType="stringCollection" />
                  <field fieldName="contact.Tags" returnType="stringCollection" />
                  <field fieldName="contact.FirstName" returnType="text" />
                  <field fieldName="contact.MiddleName" returnType="text" />
                  <field fieldName="contact.Surname" returnType="text" />
                  <field fieldName="contact.Title" returnType="text" />
                  <field fieldName="contact.FullName" returnType="text" />
                  <field fieldName="contact.Nickname" returnType="text" />
                  <field fieldName="contact.JobTitle" returnType="text" />
                  <field fieldName="contact.Suffix" returnType="text" />
                  <field fieldName="contact.IsEmpty" returnType="bool" />
                  <field fieldName="contact.BirthDate" returnType="datetime" format="yyyy-MM-dd'T'HH:mm:ss'Z'"/>
                  <field fieldName="contact.PreferredAddress.IsEmpty" returnType="bool" />
                  <field fieldName="contact.PreferredAddressKey" returnType="text" />
                  <field fieldName="contact.PreferredAddress.StateProvince" returnType="text" />
                  <field fieldName="contact.PreferredAddress.PostalCode" returnType="text" />
                  <field fieldName="contact.PreferredAddress.StreetLine1" returnType="text" />
                  <field fieldName="contact.PreferredAddress.StreetLine2" returnType="text" />
                  <field fieldName="contact.PreferredAddress.StreetLine3" returnType="text" />
                  <field fieldName="contact.PreferredAddress.City" returnType="text" />
                  <field fieldName="contact.PreferredAddress.Latitude" returnType="float" />
                  <field fieldName="contact.PreferredAddress.Longitude" returnType="float" />

                  <!--Default Sitecore IndexedVisit fields-->
                  <field fieldName="visit.TrafficType" returnType="long" />
                  <field fieldName="visit.UserAgent" returnType="text" />
                  <field fieldName="visit.CampaignId" returnType="guid" />
                  <field fieldName="visit.InteractionId" returnType="guid" />
                  <field fieldName="visit.Referrer" returnType="text" />
                  <field fieldName="visit.ReferringSite" returnType="text" />
                  <field fieldName="visit.SiteName" returnType="text" />
                  <field fieldName="visit.Value" returnType="long" />
                  <field fieldName="visit.LocationId" returnType="guid" />
                  <field fieldName="visit.VisitPageCount" returnType="long" />
                  <field fieldName="visit.ProfilePatternIds" returnType="stringCollection" />

                  <field fieldName="whois.AreaCode" returnType="text" />
                  <field fieldName="whois.BusinessName" returnType="text" />
                  <field fieldName="whois.City" returnType="text" />
                  <field fieldName="whois.Country" returnType="text" />
                  <field fieldName="whois.IspName" returnType="text" />
                  <field fieldName="whois.MetroCode" returnType="text" />
                  <field fieldName="whois.PostalCode" returnType="text" />
                  <field fieldName="whois.Region" returnType="text" />
                  <field fieldName="whois.Ip" returnType="text" />

                  <field fieldName="browser.BrowserMajorName" returnType="text" />
                  <field fieldName="browser.BrowserMinorName" returnType="text" />
                  <field fieldName="browser.BrowserVersion" returnType="text" />

                  <field fieldName="os.Name" returnType="text" />
                  <field fieldName="os.MajorVersion" returnType="text" />
                  <field fieldName="os.MinorVersion" returnType="text" />

                  <!--Default Sitecore IndexedVisitPage fields-->
                  <field fieldName="visitPage.DateTime" returnType="datetime" format="yyyy-MM-dd'T'HH:mm:ss'Z'"/>
                  <field fieldName="visitPage.Duration" returnType="long" />
                  <field fieldName="visitPage.Url" returnType="text" />
                  <field fieldName="visitPage.VisitPageIndex" returnType="long" />

                  <!--Default Sitecore IndexedVisitPageEvent fields-->
                  <field fieldName="visitPageEvent.Name" returnType="text" />
                  <field fieldName="visitPageEvent.ItemId" returnType="guid" />
                  <field fieldName="visitPageEvent.DateTime" returnType="datetime" format="yyyy-MM-dd'T'HH:mm:ss'Z'"/>
                  <field fieldName="visitPageEvent.TimeStamp" returnType="long" />
                  <field fieldName="visitPageEvent.PageEventDefinitionId" returnType="guid" />

                  <!--Default Sitecore IndexedContactTag fields-->
                  <field fieldName="contactTag.Name" returnType="text" />
                  <field fieldName="contactTag.TagValue" returnType="text" />
                  <field fieldName="contactTag.Values" returnType="stringCollection" />
                  <field fieldName="contactTag.DateTime" returnType="datetime" format="yyyy-MM-dd'T'HH:mm:ss'Z'" />
                  <field fieldName="contactTag.AcquaintanceId" returnType="guid" />

                  <!--Default Sitecore IndexedAddress fields-->
                  <field fieldName="address.isempty" returnType="bool" />
                  <field fieldName="address.city" returnType="text" />
                  <field fieldName="address.stateprovince" returnType="text" />
                  <field fieldName="address.postalcode" returnType="text" />
                  <field fieldName="address.streetline1" returnType="text" />
                  <field fieldName="address.streetline2" returnType="text" />
                  <field fieldName="address.streetline3" returnType="text" />
                  <field fieldName="address.streetline4" returnType="text" />
                  <field fieldName="address.latitude" returnType="float" />
                  <field fieldName="address.longitude" returnType="float" />
                </fieldNames>
              </fieldMap>
            </configuration>
          </index>
        </indexes>
      </configuration>
    </contentSearch>
  </sitecore>
</configuration>

My Sitecore version is 8.2 initial release (rev. 160729)
And SOLR version is 5.4.1

Although this should be valid for all sitecore versions starting from 7.x

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s