Magento – Elastic search illegal_argument_exception error “Text fields are not optimised” but it’s NOT A TEXT FIELD

elasticsearchproduct-attribute

I upgraded to 2.4.1 and elasticsearch, which I did not use before.

In my log I find the following error

"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true, "failed_shards":[{"shard":0,"index":"magento2_product_1_v4","node":"HVBmFhwfQK-VkdOPpT60-g","reason":{"type":"illegal_argument_exception", "reason":"Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [features] in order to load field data by uninverting the inverted index. Note that this can use significant memory."}}], 

(this repeats 5+ times deep)

at vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php:632

This seems to indicate it is not happy with the [features] attribute being a text field

Problem is, it is not a text field, it is a multiselect attribute with backend type varchar – I have just checked the attributes table to be sure! – so what is this error about? Also, I am not aware of aggregrating or sorting by that field anywhere, though as a multiselect field it is used in layered navigation. That's what they are designed for, no?

How should multiselect attributes be to work with layered navigation and elasticsearch?

Best Answer

I figured it out

This was a data migration caused bug, I should have remembered that data migration would incorrectly put the multiselect attributes in the text eav table not the varchar eav table - see https://github.com/magento/data-migration-tool/issues/646

I had copied my data to the right place but I had not cleared the wrong entries in the text eav table. Clearing these fixed my problem

Related Topic