Error due to large terms when rebuilding the xDB search index in Azure Search or Solr

Rebuilding the xDB search index might fail with an error when processing large terms, which are more than 32766 bytes. This happens because Azure Search and Solr providers have a limit on the maximum size of a single term in the search index. Errors similar to the following can be found in the log records:

Failed to repeat processing: key: c315df92-d019-0000-0000-054e908dff7cmsg: Field 'facets_keybehaviorcache_pageevents_data_ss' contains a term that is too large to process. The max length for UTF-8 encoded terms is 32766 bytes. The most likely cause of this error is that filtering, sorting, and/or faceting are enabled on this field, which causes the entire field value to be indexed as a single term. Please avoid the use of these options for large fields.

Sitecore must not produce such long terms. To achieve this, you must treat filterable, sortable, and facetable attributes with care and only use them when necessary (recommended).

Perform the following steps:

For Sitecore XP 9.0.2, download and install the following hotfix according to the instructions from readme.txt: SC Hotfix 309583-1.zip.
Be aware that the hotfix was built for a specific Sitecore XP version, and must not be installed on other Sitecore XP versions or in combination with other hotfixes. If any other hotfixes have already been installed on a certain Sitecore XP instance, send a request for a compatibility check to Sitecore Support.
Note that the ZIP file contents must be extracted to locate installation instructions and the related files inside.