Adding Entity Relationships to the Frontend | Yext Hitchhikers Platform

What You’ll Learn

In this section, you will learn:

  • How to add linked enity fields as display fields to use them in the frontend
  • How to customize facets and filters for entity relationship fields

Displaying Linked Entity Data on the Frontend

On the frontend of Search, any field from a linked entity can be displayed. In order to display these fields, you must:

1. Add the fields to your search configuration to the displayFields property

{
  "verticals": {
    "[verticalKey]": {
      "displayFields": [
        "c_customRelationshipField.name",
        "c_customRelationshipField.c_customField",
        "c_customRelationshipField.c_customRelationshipField2.name"
      ]
    }
  }
}

By default in the API response, we return all data fields from an entity as well as the name and entityId fields of related entities. However, you can specify additional fields you want to be returned by adding them to this displayFields property. This will allow them to used and viewable on the frontend.

If you specify display fields for a vertical, you will need to add ALL fields you want to display on the front end of that vertical. That includes fields on both related entities and base entities.

2. Add the field to a result card

Once the entity relationship data that you are looking to use is returned on the backend, you can then list it on a result card as you would with any other field. It should look something like this:

subtitle: profile.c_customRelationshipField.c_customField

Facets and Filters

Entity relationship data can also be used as a facet within Search. You can follow the Implementing Facets unit to do this. You just need to ensure that the searchable field is referenced with the proper dot notation as mentioned throughout this module.

In the backend configuration, you will set the linked entity as a facet via Edit as JSON:

{
  "verticals": {
    "ce_doctors": {
      "searchableFields": {
        "c_relatedSpecialties.c_relatedCondition.name": {
          "facet": true
        },
        "c_relatedSpecialties.name": {
          "facet": true
        }
      }
    }
  }
}

The UI should look like:

Entity Relationship as a Facet in Congif UI

If you want to customize the facet on the frontend, you will need to then add something like this to the ComponentSettings in the vertical’s JSON file:

{
  "componentSettings": {
    "Facets": {
      "fields": {
        "c_relatedSpecialties.name": {
          "label": "Restaurant Features", 
          "searchable": true,
          "searchLabelText": "Search for our features",
          "placeholderText": "Search"       
        }
      }
    }
  }
}
unit Quiz
+20 points
Daily Quiz Streak Daily Quiz Streak: 0
Quiz Accuracy Streak Quiz Accuracy Streak: 0
    Error Success Question 1 of 2

    By default, the API response returns which data fields for related entities:

    Error Success Question 2 of 2

    True or False: If you want to add an entity relationship field as a display field, you must also specify all other fields you want to appear on the frontend for that vertical.

    Way to go, you passed! 🏁

    You've already completed this quiz, so you can't earn more points.You completed this quiz in 1 attempt and earned 0 points! Feel free to review your answers and move on when you're ready.
1st attempt
0 incorrect
Feedback