Elasticsearch 5 が設定され、「Fielddata が無効になっています…」エラーで検索ページが読み込まれない

ここでは、Elasticsearch 5 で検索ページが読み込まれず、次のような例外が発生する問題を修正する方法について説明します。

{"0":"{\"error\":{\"root_cause\":[{\"type\":\"illegal_argument_exception\",\"reason\":\"Fielddata is disabled on text fields by default. Set fielddata=true on [%attribute_code%]] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory.\"}].

影響を受けるバージョン

  • Adobe Commerce 2.2.x
  • Elasticsearch v.5
NOTE
Adobe Commerce 2.3.x のElasticsearch v.5 は非推奨(廃止予定)になりました

問題

前提条件:Elasticsearch 5 が設定されていること。

検索リクエストで、次の例外がログに生成されます。

{"0":"{\"error\":{\"root_cause\":[{\"type\":\"illegal_argument_exception\",\"reason\":\"Fielddata is disabled on text fields by default. Set fielddata=true on [%attribute_code%]] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory.\"}].

原因:

デフォルトでは、レイヤーナビゲーションで使用できるのは、特定のタイプの製品属性のみです。 「Yes/No」、「Dropdown」、「Multipleselect」、「Price」です。 そのため、Commerce Admin では、他のタイプの属性をとして設定できません レイヤーナビゲーションでの使用 = フィルタリング可能 または 検索結果のレイヤー化されたナビゲーションでの使用 = はい. ただし、を直接変更することで、この制限を回避できる技術的可能性があります is_filterable および is_filterable_in_search データベース内の値。 これが発生し、日付やテキストなどの他の属性タイプがレイヤーナビゲーションで使用されるように設定されている場合、Elasticsearch 5 は例外をスローします。

これを実現するには、レイヤーナビゲーションで使用するように設定されている Dropdown、Multipleselect、Price 以外の属性があるかどうかを確認する必要があります。 次のクエリを実行して、これらの属性を検索します。

SELECT ea.attribute_code, ea.frontend_input, cea.is_filterable, cea.is_filterable_in_search FROM eav_attribute AS ea
    -> INNER JOIN catalog_eav_attribute AS cea ON ea.attribute_id = cea.`attribute_id`
    -> WHERE (is_filterable = 1 OR is_filterable_in_search = 1) AND frontend_input NOT IN ('boolean', 'multiselect', 'select', 'price');

結果には、レイヤーナビゲーションに使用される属性のリストが含まれます。このタイプでは、これを許可していません。 この問題を修正するには、次の節で説明する手順を実行します。

解決策

この問題を修正するには、を設定する必要があります is_filterable (レイヤー化されたナビゲーションで使用される)と filterable_in_search (つまり、検索結果の階層型ナビゲーションで使用されます)。「0」(使用されません)。 これを行うには、次の手順を実行します。

  1. データベースバックアップを作成します。

  2. 次のようなデータベースツールを使用します phpMyAdminまたは、コマンドラインから手動で DB にアクセスして、次の SQL クエリを実行します。

    code language-sql
    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');
    
  3. 次のコマンドを使用して、カタログ検索の完全な再インデックスを実行します。

    code language-bash
    bin/magento indexer:reindex catalogsearch_fulltext
    
  4. 次を実行してキャッシュをクリーンアップ

    code language-bash
    bin/magento cache:clean
    

または、の下のCommerce管理で確認できます。 システム > ツール > キャッシュ管理.

これで、問題なくカタログ検索を実行できるようになります。

recommendation-more-help
8bd06ef0-b3d5-4137-b74e-d7b00485808a