Keyword field type support on Elasticsearch <5.x version

Affected version
2.0.1

AddonsLab

Well-known member
#1
Hello,

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!
 

AddonsLab

Well-known member
#2
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 https://www.elastic.co/blog/strings-are-dead-long-live-strings 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!
 
Top