magento2: Magento 2.3.5p-1 and Elasticsearch 6.8.11 fielddata error
Preconditions (*)
- Magento 2.3.5p-1
- Elasticsearch 6.8.11
Steps to reproduce (*)
- Install magento using
composer create-project --repository-url=https://repo.magento.com/ magento/project-enterprise-edition=2.3.5-p1
- install Elasticsearch 6.8.11
Expected result (*)
Catalog Product page works well with updated_at sorting
Actual result (*)
Catalog Product page throw an error
[{"type":"illegal_argument_exception","reason":"Fielddata is disabled on text fields by default. Set fielddata=true on [updated_at] 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."}]
We have default sorting on the catalog by updated_at desc, if I remove this sorting all works well. Elasticsearch displays updated_at as
"updated_at" : { "type" : "text", "index" : false },
So I am not sure why this is happening if updated_at is not indexed and obviously can not be set as fielddata=true.
Previous version o magento that we have was 2.3.0 (magento2ce, now we moved to the project-community-edition) with elasticsearch 5.6 and all works well with such config.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 21 (7 by maintainers)
The actual right solution for this is to REBUILD you attributes using a different storage type (such as options). But, if you really need to keep things as they are, the solution proposed by @mlaurense is the way to go. Only that his code is not a generic approach and deals with specific hardcoded fields.
I did this to automatically deal with this:
I can confirm this works, however in my instance the array key was already set. So the below code was needed instead of !isset (your results may vary)
if (array_key_exists('your_attribute', $fields)) { $fields['your_attribute] = [ 'type' => 'keyword' ]; }
@JelleGe Depending on which ES version you’re using, you need to create a “before” plugin on method
addFieldsMapping
, changing the ES field type tokeyword
. In our case we made “after” plugin for\Magento\Elasticsearch7\Model\Client\Elasticsearch
, so ourbeforeAddFieldsMapping
looks like thisYou’ll have to do this for any category or product attributes for which magento uses the wrong ES field type
Just letting everyone know that I’m getting this same error with m2.3.5-p2 (enterprise/whatever the paid version is called) with ES 7.0