Transformers

In Sitecore Search, you can use transformers to index structured documents like CSV, XML, and JSON. Used with feed crawlers, API crawlers, and advanced web crawlers transformers can access a specific document property or object property, manipulate its value, then set that as the value of an entity's attribute.

The data in CSV, XML, and JSON, is typically lists of objects. In Search, you can use transformers to access contained properties and values as follows:

  • Document transformers can access properties at the document level. They can also manipulate their values. For example, you can use JavaScript to transform a top-level node to an indexable object. Document transformers are displayed in a flat list.

  • Attribute transformers can access the same property of every object in a list. They can also manipulate their values before indexing each object as an entity. For example, when indexing movies.json, the transformer can format every movie's release_date property to the format required by your entity's attribute. Attribute transformers are displayed in a group under an attribute name.

Important

Document transformers run first in the order they are listed, followed by attribute transformer groups, where the nested transformers run in the order listed.

The following examples describe use cases for document and attribute transformers.

No transformers required

For crawlers indexing objects or rows in a CSV as index items, you do not need transformers when:

  • The column name or field name matches an attribute of the entity.

  • The column values are in the format as required to populate the attribute.

Transform products listed in an HTML page to index them

To transform products listed in a HTML page to index them:

  1. Create a JavaScript document transformer.

  2. In the JS Source text area add the JS code to extract products as a JSON array of objects.

  3. Add attribute transformers, where required, to index a product.

Format title

To set the value for the title attribute in Snake format from the title column in a CSV:

  • For the attribute title, create a column transformation to Change case to Snake.

    The transformer assumes that the CSV has a title column.

Column and attribute do not have the same name

To set the value for the available stock attribute from the units in stock column in a CSV:

  • For the attribute available stock, create an attribute transformation to Copy from the units in stock column.

Set flag for limited stock

To set values for the limited stock attribute using the units in stock column in a CSV:

  1. For the attribute limited stock, create an attribute transformation to Copy from the units in stock column.

  2. For the attribute limited stock, create an attribute transformation by setting True/False to True when the value in the limited stock column is Less Than 100.

Do you have some feedback for us?

If you have suggestions for improving this article,