Fixed Keyword field type support on Elasticsearch <5.x version

Affected version


Well-known member

During developing our add-on, that adds a new indexable content type we used \XF\Search\MetadataStructure::KEYWORD as type of some fields. It causes an error, however, when trying to optimize the index on versions of Elasticsearch not support "keyword" field type:

XFES\Elasticsearch\RequestException: Failed to parse mapping [thread_field]: No handler for type [keyword] declared on field [field_id] in src/addons/XFES/Elasticsearch/Api.php at line 387
The solution would be, it seems, to change the type of keyword fields back to string on versions not supporting it (just as it is done for text/string type switch).

Just let me know if you need any further information.

Thank you!


Well-known member
Just an update regarding the possible fix. I have tried switching the field to type string, and here an error I get when executing a search:

Fielddata is disabled on text fields by default. Set fielddata=true on [field_id] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead.
The field in question is important to be fetched back from the index, not only searched. As it is described at this use case is a correct candidate for using keyword fields instead of text, but if using text field, we should be able to set fielddata=true for the field when creating the index. Hopefully this is possible to implement.

Thank you!

XF Bug Bot

XenForo bug fixer bot
Staff member
Thank you for reporting this issue. The issue is now resolved and we are aiming to include that in a future XFES release (2.0.2).

Change log:
Allow keyword index types to work as expected on Elasticsearch 2.x
Any changes made as a result of this issue being resolved may not be rolled out here until later.