8.1 Solr type "relation_json"

Solr does not allow storage of key/value or an array. This may get you into problems which need a lot of database queries to solve, mainly for facet fields.

The "relation_json" type allows storage of a json object into a (facet) field, which makes storage of multiple fields a lot easier.

This type can be used to store multiple properties of the relations of a content item in solr.


In your solr mapping you can add the content like this:

<type name="integrated.relation_json">
        <string key="alias">solr_alias</string>
        <string key="relation_id">integrated_relation_id</string>
        <array key="properties">
            <string key="id">id</string>
            <string key="slug">slug</string>
            <string key="title_alias">title</string>


The alias is the name for the field in solr.

The relation_id is the relationId of the relation. All the references of this relation will be stored in solr using json_encode. In the properties you have to define the properties that will be stored in solr.

The properties work the same as integrated.fields, the key is the alias, the value is the property.


You have to use a json_decode filter to read the values as an array. There is no twig json_decode filter available in integrated yet, you can build your own twig filter or use php.

Example of json_decode twig function:



class JsonDecodeExtension extends \Twig_Extension

     * @return array
public function getFilters()
        return [
            new \Twig_SimpleFilter('json_decode', [$this, 'jsonDecode']),

     * @param $jsonArray
     * @return mixed
public function jsonDecode($jsonArray)
        return json_decode($jsonArray);

     * @return string
public function getName()
        return 'json_decode';