2

I'm working with Sitecore 9 and solr 6.2.2. I am trying to create a custom index and in this index I'm only including a few fields. One of the fields is called OfficeLocation and it's a string. When rebuilding the index I'd like for the field to be called OfficeLocation and not OfficeLocation_s (or whatever the formatter in the config does). I can't seem to get this to work and I can't seem to find any posts when searching online on the topic.

Do any of you guys know how to do this?

  • Why exactly do you want to store the field as "OfficeLocation" instead of "OfficeLocation_s"? The "_s" defines the type of the field (like described here, look for Type Matches). When building a query in code you can just use .OfficeLocation, which the Sitecore Solr provider will translate to the proper field (based on your configuration). – andredezwart Feb 22 at 15:07
  • Hi Mok- Check out this documentation and see if this helps clear it up. doc.sitecore.com/developers/91/… also, welcome to Sitecore!! Best. - justin – Justin Bradley Feb 22 at 15:09
  • I think it's because at some point in time the team decided not to use the content search API or something like that. I'm new to the team so I am unsure of the history. Ideally we would want to use to use the content search API (to be more generic/streamlined etc) but it would involve some re-writing of code so we have to stick with "OfficeLocation" for now and we can revisit using content search api later when refactoring code. – Mok Feb 22 at 15:22
3

I am assuming you are using the Sitecore configuration for your custom index (in which case you should also use the api, but let's skip that discussion).

Note that I never tried what I'm explaining here, but it might get you in the right direction.. in the DefaultIndexConfiguration for Solr (defaultSolrIndexConfiguration located in Sitecore.ContentSearch.Solr.DefaultIndexConfiguration.config) you can find the typeMatches in the fieldMap. These typeMatches define the fieldNameFormat. For a string it mentions

<typeMatch typeName="string" type="System.String" fieldNameFormat="{0}_s" settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider" />

Note the "{0}_s".

First if all, create your own version of the configuration (patch it) and attach that to your index. Then you can start making adjustments..

You might change the fieldNameFormat for the string type, but that will change the value for all string fields. Another option is to create a new type and map your field to that type (in the fieldNames section).

This seems logical, but again: I didn't try this myself..

  • 2
    I think the problem here is that the field name would have to go in the Solr schema as well. The _s suffix is what maps to a dynamicField in the schema. It would be easy to add a field in older schema.xml format. Not sure how to go about it with managed-schema though – Matthew FitzGerald-Chamberlain Feb 22 at 16:27
  • I got part of it working so far. I can get indexing to work but I have to create the fields manually in solr. However if I go into the control panel and click, "Populate Solr Managed Schema" it will remove my custom fields from solr. Does anyone know how to create custom types so that you could click, "Populate Solr Managed Schema" and have it create the field in Solr? ie I create a field called "OfficeLocation" and have it create "OfficeLocation" and not "OfficeLocation_s" in Solr? – Mok Feb 25 at 21:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.