2

I've recently upgraded my Magento to 2.4 which necessitates the use of Elasticsearch.

Using the search function always shows the message "Your search returned no results". However using "Advanded Search" returns results as normal.

I've tested the connection as per this screenshot and there seems to be no issues.

enter image description here

I've checked another question regarding this (309450) but the solution there (turning off modules) doesn't seem to have fixed the issue.

I've also run the command below in SSL

curl http://localhost:9200/_cluster/health?pretty

This got the following result.

{
  "cluster_name" : "my-application",
  "status" : "yellow",
  "timed_out" : false,
  "number_of_nodes" : 1,
  "number_of_data_nodes" : 1,
  "active_primary_shards" : 4,
  "active_shards" : 4,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 4,
  "delayed_unassigned_shards" : 0,
  "number_of_pending_tasks" : 0,
  "number_of_in_flight_fetch" : 0,
  "task_max_waiting_in_queue_millis" : 0,
  "active_shards_percent_as_number" : 50.0
}

I have also looked in the exception log and found the following error which seems to relate to elasticsearch:

[2021-11-26 11:05:07] main.CRITICAL: {"error":{"root_cause":[{"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 [links_title] in order to load field data by uninverting the inverted index. Note that this can use significant memory."}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"magento2_product_1_v31","node":"r9_ZsNBiTqiP7FJDre9MmA","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 [links_title] in order to load field data by uninverting the inverted index. Note that this can use significant memory."}}],"caused_by":{"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 [links_title] in order to load field data by uninverting the inverted index. Note that this can use significant memory.","caused_by":{"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 [links_title] in order to load field data by uninverting the inverted index. Note that this can use significant memory."}}},"status":400} {"exception":"[object] (Elasticsearch\\Common\\Exceptions\\BadRequest400Exception(code: 400): {\"error\":{\"root_cause\":[{\"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 [links_title] in order to load field data by uninverting the inverted index. Note that this can use significant memory.\"}],\"type\":\"search_phase_execution_exception\",\"reason\":\"all shards failed\",\"phase\":\"query\",\"grouped\":true,\"failed_shards\":[{\"shard\":0,\"index\":\"magento2_product_1_v31\",\"node\":\"r9_ZsNBiTqiP7FJDre9MmA\",\"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 [links_title] in order to load field data by uninverting the inverted index. Note that this can use significant memory.\"}}],\"caused_by\":{\"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 [links_title] in order to load field data by uninverting the inverted index. Note that this can use significant memory.\",\"caused_by\":{\"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 [links_title] in order to load field data by uninverting the inverted index. Note that this can use significant memory.\"}}},\"status\":400} at /var/www/vhosts/sitename.co.uk/httpdocs/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php:632)"} []
[2021-11-26 11:05:12] main.CRITICAL: {"error":{"root_cause":[{"type":"query_shard_exception","reason":"failed to create query: field:[sku] was indexed without position data; cannot run PhraseQuery","index_uuid":"qI8SDvZQSFGVhINcjyR_cw","index":"magento2_product_1_v31"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"magento2_product_1_v31","node":"r9_ZsNBiTqiP7FJDre9MmA","reason":{"type":"query_shard_exception","reason":"failed to create query: field:[sku] was indexed without position data; cannot run PhraseQuery","index_uuid":"qI8SDvZQSFGVhINcjyR_cw","index":"magento2_product_1_v31","caused_by":{"type":"illegal_state_exception","reason":"field:[sku] was indexed without position data; cannot run PhraseQuery"}}}]},"status":400} {"exception":"[object] (Elasticsearch\\Common\\Exceptions\\BadRequest400Exception(code: 400): {\"error\":{\"root_cause\":[{\"type\":\"query_shard_exception\",\"reason\":\"failed to create query: field:[sku] was indexed without position data; cannot run PhraseQuery\",\"index_uuid\":\"qI8SDvZQSFGVhINcjyR_cw\",\"index\":\"magento2_product_1_v31\"}],\"type\":\"search_phase_execution_exception\",\"reason\":\"all shards failed\",\"phase\":\"query\",\"grouped\":true,\"failed_shards\":[{\"shard\":0,\"index\":\"magento2_product_1_v31\",\"node\":\"r9_ZsNBiTqiP7FJDre9MmA\",\"reason\":{\"type\":\"query_shard_exception\",\"reason\":\"failed to create query: field:[sku] was indexed without position data; cannot run PhraseQuery\",\"index_uuid\":\"qI8SDvZQSFGVhINcjyR_cw\",\"index\":\"magento2_product_1_v31\",\"caused_by\":{\"type\":\"illegal_state_exception\",\"reason\":\"field:[sku] was indexed without position data; cannot run PhraseQuery\"}}}]},\"status\":400} at /var/www/vhosts/sitename.co.uk/httpdocs/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php:632)"} []

I'd appreciate any advice on this topic.

UPDATE: ISSUE RESOLUTION

Thanks to Edgarth for his assistance, there were a few extra steps I had to perform but he pointed me in the right direction.

Essentially I had to disable the "Search" and "filter" options for some of the product attributes (I presume that SKU was the troublesome one given the error) and run the following commands in SQL:

1:

UPDATE catalog_eav_attribute 
SET is_filterable_in_search = 0 
WHERE attribute_id IN (SELECT attribute_id FROM eav_attribute WHERE entity_type_id = 4 AND backend_type = 'varchar')

2:

UPDATE catalog_eav_attribute AS cea
INNER JOIN eav_attribute AS ea
ON ea.attribute_id = cea.attribute_id
SET cea.is_filterable = 0, cea.is_filterable_in_search = 0
WHERE (cea.is_filterable = 1 OR cea.is_filterable_in_search = 1)
AND frontend_input NOT IN ('boolean', 'multiselect', 'select', 'price');

After doing this and reindexing, the search function seems to be working properly now.

4
  • Have you tried running 'php bin/magento indexer:reindex' command? Nov 16, 2021 at 11:32
  • Several times. No effect I'm afraid.
    – CJNotts
    Nov 16, 2021 at 12:03
  • You sure your elasticsearch version is 7+ ? Suggesting to double check it Nov 18, 2021 at 8:34
  • Have just run the curl command and updated the question. Doesn't seem to have a version number attached. Is this the issue?
    – CJNotts
    Nov 18, 2021 at 16:08

2 Answers 2

1

Check in your env.php file if you have

  'catalog' => [
            'search' => [
                'enable_eav_indexer' => '1',
                'engine' => 'elasticsearch7',
                'elasticsearch7_server_hostname' => 'elasticsearch'
            ]
        ],
2
  • 1
    Would that be the one in app > etc > env.php? It wasn't in there but I've added it in and run the usual SSH commands including reindex. It doesn't seem to have made any difference I'm afraid.
    – CJNotts
    Nov 25, 2021 at 15:49
  • Yes, thats the file. Keep in mind the server host name might be different in your case than in mine. Also if you still have issues maybe check github.com/Smile-SA/elasticsuite. They have a whole Wiki page on how to set it up correctly (github.com/Smile-SA/elasticsuite/wik`) Nov 26, 2021 at 8:00
4
+50

Check if you don't have any "not allowed" filterable and searchable product attributes. For Elastic they can have only 'boolean', 'multiselect', 'select', 'price' types, no "text" or "double" ones that might work on MySql

This is the fix we used:

UPDATE catalog_eav_attribute AS cea
INNER JOIN eav_attribute AS ea
ON ea.attribute_id = cea.attribute_id
SET cea.is_filterable = 0, cea.is_filterable_in_search = 0
WHERE (cea.is_filterable = 1 OR cea.is_filterable_in_search = 1)
AND frontend_input NOT IN ('boolean', 'multiselect', 'select', 'price');

Also nothing in logs? No errors when reindexing?

2
  • I've also run the fix in PHP myadmin and nothing has changed. I've set all atributes to non-searchable and filterable except for name, info, status and url_key. I've noticed that some attributes in the Database such as "available_sort_by" has a frontend_input_renderer vaue of "Magento\Catalog\Block\Adminhtml\Category\Helper\Pricestep" but I'm not sure this is affecting anything. There was also an "illegal_argument_exception" in the exception log which I have now added to the question, would this have anything to do with it?
    – CJNotts
    Nov 26, 2021 at 11:15
  • 1
    Thanks for pointing me in the right direction. I've updated the question with the resolution that I used.
    – CJNotts
    Nov 26, 2021 at 12:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.