Search code examples
solrlucenefacetsolrcloudsolr-schema

Is there ever a reason for copying fields in to a facet field in the index?


I'm looking at a very old solr instance (4-6 years since last touched), and I am seeing these extra dynamic fields, 'f_' and 'fs_' for multi and single valued facet fields.

My understanding, though, is that facets only happen in query-time.

Also, it's just a copy over - the fields dont change type.

So before I nuke these fields to kingdom come; is there a reason for facet fields in an index that is just a copied field?

Thanks


Solution

  • Facets only happening query time is a bit of a misnomer - the content (the tokens) that the facet represents from is generated when indexing. The facet gives the distinct number of documents that has a specific token present.

    That means that if the field type is identical and there is only one field being copied into the other named field, the behaviour between the source and the destination field should be identical.

    However, if there are multiple fields copying content into the same field, the results will differ. Also be aware that the type is given from the schema for the field, it's not changed by the copyField instruction in any way. A copy field operation happens before any content runs through the indexing chain for the field.

    Usually you want facets to be generated on string fields so that the indexed values are kept as-is, while you want to use a text field or similar for searching (with tokenization), since a string field would only give exact (including matching case) hits.