Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elasticsuite 2.9 unable to load correct spelling type (ES 6.x) #1852

Closed
ahajji06 opened this issue Jun 16, 2020 · 5 comments
Closed

Elasticsuite 2.9 unable to load correct spelling type (ES 6.x) #1852

ahajji06 opened this issue Jun 16, 2020 · 5 comments
Assignees
Labels

Comments

@ahajji06
Copy link

Preconditions

Magento Version : CE 2,3.5
Elasticsearch Version: 6.8.8
ElasticSuite Version : 2.9.0
Environment : Developer

Expected result

spelling type should be defined correctly

Actual result

It always returns: self::SPELLING_TYPE_EXACT
(from catch block in src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Spellchecker.php)

Logs:
Request Failure: {"method":"POST","uri":"http://localhost/magento2_de_catalog_product/_termvectors?term_statistics=true&fields=spelling%2Cspelling.whitespace","port":9200,"headers":{"Host":["localhost"],"Content-Type":["application/json"],"Accept":["application/json"],"User-Agent":["elasticsearch-php/7.7.0 (Linux 4.19.0-9-amd64; PHP 7.3.19)"]},"HTTP code":400,"duration":0.000577,"error":"{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"request [/magento2_de_catalog_product/_termvectors] contains unrecognized parameters: [fields], [term_statistics]"}],"type":"illegal_argument_exception","reason":"request [/magento2_de_catalog_product/_termvectors] contains unrecognized parameters: [fields], [term_statistics]"},"status":400}"} []
Response ["{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"request [/magento2_de_catalog_product/_termvectors] contains unrecognized parameters: [fields], [term_statistics]"}],"type":"illegal_argument_exception","reason":"request [/magento2_de_catalog_product/_termvectors] contains unrecognized parameters: [fields], [term_statistics]"},"status":400}"] []
curl -XPOST 'http://localhost/magento2_de_catalog_product/_termvectors?term_statistics=true&fields=spelling%2Cspelling.whitespace' -d '{"doc":{"spelling":"fnster"}}' [] []

Any idea how i can fix that?
Thank you

@rbayet rbayet self-assigned this Jun 16, 2020
@ahajji06
Copy link
Author

ahajji06 commented Jun 16, 2020

the solution is to add the type to the request since it is needed for ES 6.8.8.
It should be added to this function:
(in src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Spellchecker.php)

    private function getTermVectors(RequestInterface $request)
    {
        $termVectorsQuery = [
            'index'           => $request->getIndex(),
            'term_statistics' => true,
            'type'            => '_doc',
            'fields'          => [
                MappingInterface::DEFAULT_SPELLING_FIELD,
                MappingInterface::DEFAULT_SPELLING_FIELD . "." . FieldInterface::ANALYZER_WHITESPACE,
            ],
        ];

        $termVectorsQuery['body']['doc'] = [MappingInterface::DEFAULT_SPELLING_FIELD => $request->getQueryText()];

        return $this->client->termvectors($termVectorsQuery);
    }

the only problem that remains now is that this function is private, so we can´t modify its behavior via plugin :-(

Any ideas how to tackle that without risking update problems?

@rbayet rbayet added the bug label Jun 16, 2020
@rbayet
Copy link
Collaborator

rbayet commented Jun 16, 2020

Hello @ahajji06,

Edit: confirmed with Elasticsearch 6.8.3

The easiest way for you is to use a composer patch, using cweagans/composer-patches.
See also https://devdocs.magento.com/guides/v2.3/comp-mgr/patching.html#composer
It will fail by design to apply the patch when the bug is fixed and a new 2.9.x release of Elasticsuite is published.

In your case, for ES 6.8.x, the patch would be

diff --git a/src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Spellchecker.php b/src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Spellchecker.php
index 44ae906d..919f4d88 100644
--- a/src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Spellchecker.php
+++ b/src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Spellchecker.php
@@ -142,6 +142,7 @@ class Spellchecker implements SpellcheckerInterface
     {
         $termVectorsQuery = [
             'index'           => $request->getIndex(),
+            'type'            => '_doc',
             'term_statistics' => true,
             'fields'          => [
                 MappingInterface::DEFAULT_SPELLING_FIELD,

On our side, we will have to find a satisfying approach for both ES 6 and ES 7.

Regards,

@rbayet rbayet assigned romainruaud and ahajji06 and unassigned rbayet Jun 16, 2020
@rbayet
Copy link
Collaborator

rbayet commented Jun 16, 2020

Hello @ahajji06,

I've just checked, Elasticsearch 7.x still accepts the _doc parameter for termVectors even if it is not present in the documentation and the returned data, even if not strictly speaking the same (fields ordered differently), is consistent with or without the parameter that is required for Elasticsearch 6.x.

Long story short, feel free to submit us a PR if you wish.

Regards,

@rbayet rbayet changed the title Elasticsuite unable to load correct spelling type Elasticsuite 2.9 unable to load correct spelling type (ES 6.x) Jun 16, 2020
@ahajji06
Copy link
Author

Thank you 😊

@rbayet
Copy link
Collaborator

rbayet commented Jun 17, 2020

Re-opening because we need to fix that for everyone :)

@rbayet rbayet assigned rbayet and unassigned romainruaud Jun 17, 2020
@rbayet rbayet assigned romainruaud and unassigned rbayet Jun 17, 2020
romainruaud added a commit that referenced this issue Jul 31, 2020
…-type-parameter

Fixes #1852 termVectors restoring type parameter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants