0

I'm trying to setup Elastic Search on an existing catalog that works fine under standard MySQL search. I go through the documentation and it seems straightforward. This is Magento 2.3.2 and ElasticSearch 6 (version 6.7.1).

The documentation says to just select it and reindex. It feels like there must be some extra step that I'm not clear on. After doing so, all I get on every category page is "We can't find products matching the selection."

I've done all of the basics (clearing all caches and temp files, reindexing). The solution found here is not a change to what my file already has (copied below). Again, these are established categories and they are all empty.

What am I missing? Or, what should I be looking for?

Edit: if it helps here is the result of curl -i http://localhost:9200/_cluster/health

HTTP/1.1 200 OK
content-type: application/json; charset=UTF-8
content-length: 389

{"cluster_name":"elasticsearch","status":"yellow","timed_out":false,"number_of_nodes":1,"number_of_data_nodes":1,"active_primary_shards":5,"active_shards":5,"relocating_shards":0,"initializing_shards":0,"unassigned_shards":5,"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}

Edit: Per the comment below I've included the source of the file vendor/magento/module-elasticsearch/Model/ResourceModel/Fulltext/Collection/SearchResultApplier.php:

This is Magento 2.3.2 and I don't make local edits to vendor files.

    namespace Magento\Elasticsearch\Model\ResourceModel\Fulltext\Collection;
    
    use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\SearchResultApplierInterface;
    use Magento\Framework\Data\Collection;
    use Magento\Framework\Api\Search\SearchResultInterface;
    
    /**
     * Resolve specific attributes for search criteria.
     */
    class SearchResultApplier implements SearchResultApplierInterface
    {
        /**
         * @var Collection|\Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection
         */
        private $collection;
    
        /**
         * @var SearchResultInterface
         */
        private $searchResult;
    
        /**
         * @param Collection $collection
         * @param SearchResultInterface $searchResult
         */
        public function __construct(
            Collection $collection,
            SearchResultInterface $searchResult
        ) {
            $this->collection = $collection;
            $this->searchResult = $searchResult;
        }
    
        /**
         * @inheritdoc
         */
        public function apply()
        {
            if (empty($this->searchResult->getItems())) {
                $this->collection->getSelect()->where('NULL');
                return;
            }
            $ids = [];
            foreach ($this->searchResult->getItems() as $item) {
                $ids[] = (int)$item->getId();
            }
            $this->collection->setPageSize(null);
            $this->collection->getSelect()->where('e.entity_id IN (?)', $ids);
            $orderList = join(',', $ids);
            $this->collection->getSelect()->reset(\Magento\Framework\DB\Select::ORDER);
            $this->collection->getSelect()->order("FIELD(e.entity_id,$orderList)");
        }
    }

Progress: In exceptions.log I have the error: "type":"query_shard_exception", "reason":"No mapping found for [position_category_#] in order to sort on"

The whole thing:

main.CRITICAL: {"error":{"root_cause":[{"type":"query_shard_exception","reason":"No mapping found for [position_category_104] in order to sort on","index_uuid":"bLDcJEDeQ_eyRQOQYHppzQ",
"index":"magento2_product_1_v1"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"magento2_product_1_v1","node":"ZGUdm6aHRU6RShqrqU3xfQ","reason":{"type":"query_shard_exception","reason":"No mapping found for [position_category_104] in order to sort on","index_uuid":"bLDcJEDeQ_eyRQOQYHppzQ","index":"magento2_product_1_v1"}}]},"status":400} {"exception":"[object] (Elasticsearch\\Common\\Exceptions\\BadRequest400Exception(code: 400): {\"error\":{\"root_cause\":[{\"type\":\"query_shard_exception\",\"reason\":\"No mapping found for [position_category_104] in order to sort on\",\"index_uuid\":\"bLDcJEDeQ_eyRQOQYHppzQ\",\"index\":\"magento2_product_1_v1\"}],\"type\":\"search_phase_execution_exception\",\"reason\":\"all shards failed\",\"phase\":\"query\",\"grouped\":true,\"failed_shards\":[{\"shard\":0,\"index\":\"magento2_product_1_v1\",\"node\":\"ZGUdm6aHRU6RShqrqU3xfQ\",\"reason\":{\"type\":\"query_shard_exception\",\"reason\":\"No mapping found for [position_category_104] in order to sort on\",\"index_uuid\":\"bLDcJEDeQ_eyRQOQYHppzQ\",\"index\":\"magento2_product_1_v1\"}}]},\"status\":400} at /opt/bitnami/apps/magento/htdocs/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php:636)"} []
2
  • post this file code - Magento\Elasticsearch\Model\ResourceModel\Fulltext\Collection\SearchResultApplier.php
    – sandip
    Nov 11, 2020 at 16:02
  • What is the output of the curl http://localhost:9200/_cat/indices command execution against your ES instance?
    – Diana
    Mar 5, 2021 at 8:24

2 Answers 2

0

I was able to fix this by renaming the index. It was by default named "magento2" and I renamed it to "mydomain". Did that and reindexed and the error went away. My guess right now is that reindex wasn't taking for some reason on the default index.

(Stores -> Configuration -> Catalog -> Catalog -> Catalog Search -> Elasticsearch Index Prefix)

I was asked for the results of curl http://localhost:9200/_cat/indices

Here it is now:

yellow open mydomain_product_1_v1     vAbKxQUiQkS7uHdmp-uDCg 5 1 1484 0 1.3mb 1.3mb
yellow open magento2_product_1_v1     bLDcJEDeQ_eyRQOQYHppzQ 5 1    0 0 1.2kb 1.2kb
0

Make sore to select website in the stock settings. enter image description here

Your Answer

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

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