elastic / app-search-magento

A first party module to integrate Elastic App Search in Magento 2.
https://www.elastic.co/products/app-search
Open Software License 3.0
26 stars 11 forks source link

Unable To Find sku_value #65

Closed saderra closed 5 years ago

saderra commented 5 years ago

Received the following errors this morning on my staging 2.3.2 environment and my development 2.3.3 environment: Exception #0 (Magento\Framework\Exception\LocalizedException): Unable to find field sku_value.

Staging: This event happened when trying to search or navigate into the Magento catalog. https://c9.saderra.com/catalog/category/view/s/boat-covers/id/12/

Development: Same condition to reproduce: https://classic.saderra.com/patio/shop-by-collection/storigami

afoucret commented 5 years ago

Hi, I will need much more context on what are you trying to achieve.

From my understanding, your are trying to build a facet on the SKU but this attribute can not be set as filterable by default in Magento.

Are you using a different SKU attribute (sku_value) or the standard SKU attribute to do it? If using another attribute, how is this attribute configured (is filterable ? Backend model model ? Source model?)

Another question I have is what third party module is installed that can modify the search default behavior our layered navigation?

romain-chanu commented 5 years ago

@saderra - please do not provide any credentials. This is a public repository. @afoucret and I will follow-up with you regarding your issue.

saderra commented 5 years ago

@afoucret @afoucret you are MORE than welcome to login to the credentials I sent and make adjustments as needed to the extension. That's a dev server that I'm only keeping up and running for the purposes of ensuring this extension works. Once we verify the extension works I'm shutting that down.

afoucret commented 5 years ago

Hi @saderra, I have double-checked and the bug is caused by a third party extension.

The Amasty Part Finder module ha a logic to create facet on a field called sku_value that does not exist in Magento standard search engine. You can find the declaration in the vendor/amasty/finder/etc/search_request.xml file:

<bucket name="sku_value_bucket" field="sku_value" xsi:type="termBucket">
   <metrics>
       <metric type="count"/>
    </metrics>
</bucket>

Because this field does not exist in the Magento standard search engine they had to implement their own logic to add it into the ElasticSearch indexing (code located inside vendor/amasty/finder/Plugin/Elasticsearch). Unfortunately, the same work needs to be done with AppSearch in order to get things working as expected.

From what I have seen this field is a pure copy of the SKU field (added for technical reasons that are related to ElasticSearch). The most straightforward method to deal with this issue is probably to try to use the sku field in the Amasty search requests instead of sku_value. In the context of App Search the distinction does not make sense since we do not let the control over analysis like in ElasticSearch.

To be complete on this issue, I don't consider it as an issue of the App Search module but more as an issue related to the third party module.

It is likely that you will meet additional issues with this module because it changes heavily the behavior of Magento search engine (to build something which is not related to search). Moreover, it is designed without considering other search engines than those shipped with Magento out-of-the-box. Sadly, there is nothing we can do about this and this is something I often have to deal with in the past with modules from Amasty.

afoucret commented 5 years ago

To override the field used by Amasty in the search request:

  1. Create a new module (Saderra_AppSearchPartFinder in my example)

  2. Create the Saderra\AppSearchPartFinder\etc\search_request.xml file with the following content:

<?xml version="1.0"?>

<requests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:noNamespaceSchemaLocation="urn:magento:framework:Search/etc/search_request.xsd">
    <request query="catalog_view_container">
        <aggregations>
            <bucket name="sku_value_bucket" field="sku" xsi:type="termBucket">
                <metrics>
                    <metric type="count"/>
                </metrics>
            </bucket>
        </aggregations>
    </request>

    <request query="quick_search_container">
        <aggregations>
            <bucket name="sku_value_bucket" field="sku" xsi:type="termBucket">
                <metrics>
                    <metric type="count"/>
                </metrics>
            </bucket>
        </aggregations>
    </request>
</requests>
  1. Make sure your module is loaded after Elastic AppSearch and Amasty Parts finder:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Saderra_AppSearchPartFinder" setup_version="0.0.1">
        <sequence>
            <module name="ElasticAppSearch_CatalogSearch" />
            <module name="Amasty_Finder" />
        </sequence>
    </module>
</config>
  1. Clean cache and refresh
afoucret commented 5 years ago

I close the issue because it is clearly not a bug of the module but a problem caused by a third party module.

I would be happy to continue the discussion on the proposed workaround.

saderra commented 5 years ago

I get the following error when attempting to enable the module:

There are no commands defined in the "module" namespace.

On Oct 15, 2019, at 6:01 AM, Aurélien FOUCRET notifications@github.com wrote:

To override the field used by Amasty in the search request:

Create a new module (Saderra_AppSearchPartFinder in my example)

Create the Saderra\AppSearchPartFinder\etc\search_request.xml file with the following content:

<?xml version="1.0"?>

<requests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Search/etc/search_request.xsd">

<request query="quick_search_container">
    <aggregations>
        <bucket name="sku_value_bucket" field="sku" xsi:type="termBucket">
            <metrics>
                <metric type="count"/>
            </metrics>
        </bucket>
    </aggregations>
</request>

Make sure your module is loaded after Elastic AppSearch and Amasty Parts finder:

Clean cache and refresh — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/elastic/app-search-magento/issues/65?email_source=notifications&email_token=ADDO4AMJQ6TFLNHMMXKMGXTQOW5KDA5CNFSM4JASLFE2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBIU5OQ#issuecomment-542199482, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADDO4AMOEJYHHXYBUWJSXOLQOW5KDANCNFSM4JASLFEQ.

saderra commented 5 years ago

Where does this code go?

On Oct 15, 2019, at 6:01 AM, Aurélien FOUCRET notifications@github.com wrote:

afoucret commented 5 years ago

Here is a step by step guide of how to create the module (inspired by this official Magento doc).

  1. Create the module directory in app/code:
mkdir app/code/Saderra/AppSearchPartFinder/etc
  1. Create the app/code/Saderra/AppSearchPartFinder/etc/module.xml file:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Saderra_AppSearchPartFinder" setup_version="0.0.1">
        <sequence>
            <module name="ElasticAppSearch_CatalogSearch" />
            <module name="Amasty_Finder" />
        </sequence>
    </module>
</config>

Note: We want to make sure the module is loaded after both ElasticAppSearch_CatalogSearch and Amasty_Finder modules in order to rewrite their XML files.

  1. Create the module registration file app/code/Saderra/AppSearchPartFinder/registration.php:
<?php 
\Magento\Framework\Component\ComponentRegistrar::register(
  \Magento\Framework\Component\ComponentRegistrar::MODULE, 
  'Saderra_AppSearchPartFinder',
  __DIR__
);
  1. Add the search request customization file app/code/Saderra/AppSearchPartFinder/etc/search_request.xml:
<?xml version="1.0"?>

<requests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:noNamespaceSchemaLocation="urn:magento:framework:Search/etc/search_request.xsd">
    <request query="catalog_view_container" index="catalogsearch_fulltext">
        <dimensions>
            <dimension name="scope" value="default"/>
        </dimensions>
        <queries>
            <query xsi:type="boolQuery" name="catalog_view_container" boost="1">
                <queryReference clause="must" ref="category"/>
                <queryReference clause="must" ref="price"/>
                <queryReference clause="must" ref="visibility"/>
                <queryReference clause="should" ref="sku"/>
            </query>
            <query xsi:type="filteredQuery" name="category">
                <filterReference clause="must" ref="category_filter"/>
            </query>
            <query xsi:type="filteredQuery" name="price">
                <filterReference clause="must" ref="price_filter"/>
            </query>
            <query xsi:type="filteredQuery" name="visibility">
                <filterReference clause="must" ref="visibility_filter"/>
            </query>
            <query name="sku" xsi:type="filteredQuery">
                <filterReference clause="must" ref="sku_filter"/>
            </query>
        </queries>
        <filters>
            <filter xsi:type="termFilter" name="category_filter" field="category_ids" value="$category_ids$"/>
            <filter xsi:type="rangeFilter" name="price_filter" field="price" from="$price.from$" to="$price.to$"/>
            <filter xsi:type="termFilter" name="visibility_filter" field="visibility" value="$visibility$"/>
            <filter xsi:type="termFilter" name="sku_filter" field="sku" value="$sku$"/>
        </filters>
        <aggregations>
            <bucket name="price_bucket" field="price" xsi:type="dynamicBucket" method="$price_dynamic_algorithm$">
                <metrics>
                    <metric type="count"/>
                </metrics>
            </bucket>
            <bucket name="category_bucket" field="category_ids" xsi:type="termBucket">
                <metrics>
                    <metric type="count"/>
                </metrics>
            </bucket>
            <bucket name="sku_bucket" field="sku" xsi:type="termBucket">
                <metrics>
                    <metric type="count"/>
                </metrics>
            </bucket>
            <bucket name="sku_value_bucket" field="sku" xsi:type="termBucket">
                <metrics>
                    <metric type="count"/>
                </metrics>
            </bucket>
        </aggregations>
        <from>0</from>
        <size>10000</size>
    </request>

    <request query="quick_search_container" index="catalogsearch_fulltext">
        <dimensions>
            <dimension name="scope" value="default"/>
        </dimensions>
        <queries>
            <query xsi:type="boolQuery" name="quick_search_container" boost="1">
                <queryReference clause="must" ref="sku"/>
            </query>
            <query name="sku" xsi:type="filteredQuery">
                <filterReference clause="must" ref="sku_filter"/>
            </query>
        </queries>
        <filters>
            <filter xsi:type="termFilter" name="sku_filter" field="sku" value="$sku$"/>
        </filters>
        <aggregations>
            <bucket name="sku_bucket" field="sku" xsi:type="termBucket">
                <metrics>
                    <metric type="count"/>
                </metrics>
            </bucket>
            <bucket name="sku_value_bucket" field="sku" xsi:type="termBucket">
                <metrics>
                    <metric type="count"/>
                </metrics>
            </bucket>
        </aggregations>
        <from>0</from>
        <size>10000</size>
    </request>
</requests>
  1. Setup the module:
bin/magento cache:clean
bin/magento setup:upgrade
saderra commented 5 years ago

Please see errors output by this recommendation:

https://c1.saderra.com/rv https://c1.saderra.com/rv

On Oct 16, 2019, at 9:48 AM, Aurélien FOUCRET notifications@github.com wrote:

Here is a step by step guide of how to create the module (inspired by this official Magento doc https://devdocs.magento.com/videos/fundamentals/create-a-new-module/).

Create the module directory in app/code: mkdir app/code/Saderra/AppSearchPartFinder/etc Create the app/code/Saderra/AppSearchPartFinder/etc/module.xml file:

Note: We want to make sure the module is loaded after both ElasticAppSearch_CatalogSearch and Amasty_Finder modules in order to rewrite their XML files.

Create the module registration file app/code/Saderra/AppSearchPartFinder/registration.php: <?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Saderra_AppSearchPartFinder', DIR ); Add the search request customization file app/code/Saderra/AppSearchPartFinder/etc/search_request.xml: <?xml version="1.0"?>

<requests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Search/etc/search_request.xsd">

<request query="quick_search_container">
    <aggregations>
        <bucket name="sku_value_bucket" field="sku" xsi:type="termBucket">
            <metrics>
                <metric type="count"/>
            </metrics>
        </bucket>
    </aggregations>
</request>

Setup the module: bin/magento cache:clean bin/magento setup:upgrade — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/elastic/app-search-magento/issues/65?email_source=notifications&email_token=ADDO4AJ4CLFDCJYULJIXWX3QO4ZWJA5CNFSM4JASLFE2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBM7SKY#issuecomment-542767403, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADDO4AKXCZCUK32ROGY2KMDQO4ZWJANCNFSM4JASLFEQ.

saderra commented 5 years ago

This does load after the other modules:

    'Amasty_BannersLite' => 1,
    'Amasty_Base' => 1,
    'Amasty_Geoip' => 1,
    'Amasty_Conditions' => 1,
    'Amasty_Coupons' => 1,
    'Amasty_CronScheduleList' => 1,
    'Amasty_Customform' => 0,
    'Amasty_Finder' => 1,
    'Amasty_Followup' => 1,
    'Amasty_Checkout' => 0,
    'Amasty_InvisibleCaptcha' => 0,
    'Amasty_ProductAttachment' => 1,
    'Amasty_Promo' => 1,
    'Amasty_PromoBanners' => 1,
    'Amasty_Rgrid' => 1,
    'Amasty_SalesRuleWizard' => 1,
    'Amasty_SeoRichData' => 1,
    'Amasty_Smtp' => 1,
    'Amasty_XmlSitemap' => 1,
    'Amazon_Core' => 0,
    'Amazon_Login' => 0,
    'Amazon_Payment' => 0,
    'Bazaarvoice_Connector' => 1,
    'Cart2Quote_Quotation' => 1,
    'Cart2Quote_Features' => 1,
    'Cart2Quote_FormReqDisabler' => 1,
    'Cart2Quote_License' => 1,
    'Cart2Quote_AutoProposal' => 1,
    'ClassicAccessories_IO' => 1,
    'ClassyLlama_AvaTax' => 1,
    'Dotdigitalgroup_Email' => 0,
    'ElasticAppSearch_Search' => 1,
    'ElasticAppSearch_Synonyms' => 1,
    'ElasticAppSearch_CatalogSearch' => 1,
    'ElasticAppSearch_CatalogGraphQl' => 1,
    'Firebear_ImportExport' => 1,
    'Iazel_RegenProductUrl' => 1,
    'Klarna_Core' => 0,
    'Klarna_Ordermanagement' => 0,
    'Klarna_Kp' => 0,
    'Magento_PaypalReCaptcha' => 1,
    'MSP_TwoFactorAuth' => 1,
    'MagePal_CheckoutSuccessMiscScript' => 1,
    'MagePal_Reindex' => 1,
    'Magefan_WysiwygAdvanced' => 0,
    'Mageplaza_Core' => 1,
    'Mageplaza_GoogleRecaptcha' => 1,
    'Mageplaza_Security' => 0,
    'Mageplaza_TwoFactorAuth' => 0,
    'Mexbs_Tieredcoupon' => 1,
    'Mirasvit_Core' => 1,
    'Mirasvit_Feed' => 1,
    'Mirasvit_Kb' => 1,
    'Mirasvit_Misspell' => 0,
    'Mirasvit_Report' => 1,
    'Mirasvit_Search' => 0,
    'Mirasvit_SearchAutocomplete' => 0,
    'Mirasvit_SearchElastic' => 0,
    'Mirasvit_SearchElasticNative' => 0,
    'Mirasvit_SearchLanding' => 0,
    'Mirasvit_SearchMysql' => 0,
    'Mirasvit_SearchReport' => 0,
    'Mirasvit_Sorting' => 0,
    'Saderra_AppSearchPartFinder' => 1,
    'Scriptlodge_UrlRewrite' => 1,
    'Solwin_Bannerslider' => 1,
    'Solwin_Base' => 1,
    'Solwin_CatalogPages' => 1,
    'Solwin_Core' => 1,
    'Solwin_Instagram' => 1,
    'Temando_Shipping' => 0,
    'Vertex_Tax' => 0,
    'WeltPixel_Backend' => 1,
    'WeltPixel_MobileDetect' => 1,
    'WeltPixel_Newsletter' => 1

On Oct 16, 2019, at 9:48 AM, Aurélien FOUCRET notifications@github.com wrote:

Here is a step by step guide of how to create the module (inspired by this official Magento doc https://devdocs.magento.com/videos/fundamentals/create-a-new-module/).

Create the module directory in app/code: mkdir app/code/Saderra/AppSearchPartFinder/etc Create the app/code/Saderra/AppSearchPartFinder/etc/module.xml file:

Note: We want to make sure the module is loaded after both ElasticAppSearch_CatalogSearch and Amasty_Finder modules in order to rewrite their XML files.

Create the module registration file app/code/Saderra/AppSearchPartFinder/registration.php: <?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Saderra_AppSearchPartFinder', DIR ); Add the search request customization file app/code/Saderra/AppSearchPartFinder/etc/search_request.xml: <?xml version="1.0"?>

<requests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Search/etc/search_request.xsd">

<request query="quick_search_container">
    <aggregations>
        <bucket name="sku_value_bucket" field="sku" xsi:type="termBucket">
            <metrics>
                <metric type="count"/>
            </metrics>
        </bucket>
    </aggregations>
</request>

Setup the module: bin/magento cache:clean bin/magento setup:upgrade — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/elastic/app-search-magento/issues/65?email_source=notifications&email_token=ADDO4AJ4CLFDCJYULJIXWX3QO4ZWJA5CNFSM4JASLFE2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBM7SKY#issuecomment-542767403, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADDO4AKXCZCUK32ROGY2KMDQO4ZWJANCNFSM4JASLFEQ.

afoucret commented 5 years ago

I have updated the content of the search_request.xml file in my previous comment. You should try updating it and clean the cache again.

saderra commented 5 years ago

Excellent. Appears to be working. Do you know when the rest of the functions will also be working? https://swiftype.com/solutions/magento-search https://swiftype.com/solutions/magento-search

On Oct 16, 2019, at 10:48 PM, Aurélien FOUCRET notifications@github.com wrote:

I have updated the content of the search_request.xml file in my previous comment. You should try updating it and clean the cache again.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/elastic/app-search-magento/issues/65?email_source=notifications&email_token=ADDO4AJXURN7CLOTFEARBULQO7VB3A5CNFSM4JASLFE2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBOYKFI#issuecomment-542999829, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADDO4AJ5ZPXOBX52AEQT5DTQO7VB3ANCNFSM4JASLFEQ.