magento2: Multivalued filters don't work correctly with ElasticSearch

Preconditions

  1. Install Magento 2.2.6 and ES 5.x
  2. Create a multiselect filterable attribute and assign 3 values to it : “A”, “B”, “C”
  3. Create a category, an enabled product and select “A” and “C” values for the previous attribute. Put the product in the category.
  4. Configure ES as search engine
  5. Reindex all

Steps to reproduce

  1. Go to the category page, the product should be displayed

Expected result

  1. In the filter block the attribute should appear with the options “A” and “C” (the only values with non-null result after filtering)

Actual result

  1. The filter won’t appear.

The cause seems to be because the attribute is registered in ES with the keyword analyzer which creates a single term with the attribute’s option IDs (let’s say “23 24”) and the search request is sent with the term query which searches for an exact match for each option ID (let’s say “23” or “24”, which obviously won’t match here).

Of course, switching to MySQL search engine instead of ES solves the issue.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 25 (15 by maintainers)

Most upvoted comments

Preconditions

# Import GPG Key
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -

# Install ElasticSearch 5.6 on Debian Stretch
sudo apt-get install apt-transport-https
echo "deb https://artifacts.elastic.co/packages/5.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-5.x.list
sudo apt-get update && sudo apt-get install elasticsearch

Magento 2.3-develop commit d7012b2ca1495676478d8afed8bf016ccd03bc8a

Steps to reproduce

  1. Login to admin
  2. Create Simple Product 1 and assign it to Category 1 during the product creation(it will be existing product that got an attribute later)
  3. Navigate to Stores -> Attributes -> Product
  4. Click Add New Attribute
  • Default label attr_multisel
  • Catalog Input Type for Store Owner Multiple Select
  • Options: A, B, C (none of them is required or default)
  • Advanced Attribute Properties:
  • Scope: Global
  • Storefront Properties:
  • Use in Search Yes
  • Use in Layered Navigation: Filterable (with results)
  1. Click Save Attribute
  2. Navigate to Stores -> Attributes -> Attribute Set
  3. Add attr_multisel to the Default attribute set
  4. Perform Full Reindex and Flush Cache
  5. Edit Simple Product 1 to add A and C values and Save the product
  6. Create Simple Product 2 and assign it to Category 2 and Category 1
  7. Navigate to Stores -> Configuration -> Catalog -> Catalog -> Catalog Search and set Search Engine to Elasticsearch 5.0+ then press Test Connection
  8. Verify that button value changed to Successful! Test again? and click Save Config
  9. Perform Full Reindex and Flush Cache
  10. Navigate to Category 1 and Category 2

Expected result

In the filter block the attribute should appear with the options “A” and “C” (the only values with non-null result after filtering)

Actual result

There has been an error processing your request Exception printing is disabled by default for security reasons.

Error log record number: XXXXXXXXXXXX

Exception log:

{"0":"Notice: Undefined index: manufacturer_bucket in \/var\/www\/html\/pr\/app\/code\/Magento\/Elasticsearch\/SearchAdapter\/Aggregation\/Builder\/Term.php on line 23","1":"#0 \/var\/www\/html\/pr\/app\/code\/Magento\/Elasticsearch\/SearchAdapter\/Aggregation\/Builder\/Term.php(23): Magento\\Framework\\App\\ErrorHandler->handler(8, 'Undefined index...', '\/var\/www\/html\/p...', 23, Array)\n#1 \/var\/www\/html\/pr\/app\/code\/Magento\/Elasticsearch\/SearchAdapter\/Aggregation\/Builder.php(90): Magento\\Elasticsearch\\SearchAdapter\\Aggregation\\Builder\\Term->build(Object(Magento\\Framework\\Search\\Request\\Aggregation\\TermBucket), Array, Array, Object(Magento\\Elasticsearch\\SearchAdapter\\Dynamic\\DataProvider))\n#2 \/var\/www\/html\/pr\/app\/code\/Magento\/Elasticsearch\/Elasticsearch5\/SearchAdapter\/Adapter.php(127): Magento\\Elasticsearch\\SearchAdapter\\Aggregation\\Builder->build(Object(Magento\\Framework\\Search\\Request), Array)\n#3 \/var\/www\/html\/pr\/app\/code\/Magento\/Search\/Model\/SearchEngine.php(42): Magento\\Elasticsearch\\Elasticsearch5\\SearchAdapter\\Adapter->query(Object(Magento\\Framework\\Search\\Request))\n#4 \/var\/www\/html\/pr\/lib\/internal\/Magento\/Framework\/Search\/Search.php(72): Magento\\Search\\Model\\SearchEngine->search(Object(Magento\\Framework\\Search\\Request))\n#5 \/var\/www\/html\/pr\/app\/code\/Magento\/CatalogSearch\/Model\/ResourceModel\/Fulltext\/Collection.php(359): Magento\\Framework\\Search\\Search->search(Object(Magento\\Framework\\Api\\Search\\SearchCriteria))\n#6 \/var\/www\/html\/pr\/lib\/internal\/Magento\/Framework\/Data\/Collection\/AbstractDb.php(341): Magento\\CatalogSearch\\Model\\ResourceModel\\Fulltext\\Collection->_renderFiltersBefore()\n#7 \/var\/www\/html\/pr\/app\/code\/Magento\/CatalogSearch\/Model\/ResourceModel\/Fulltext\/Collection.php(409): Magento\\Framework\\Data\\Collection\\AbstractDb->_renderFilters()\n#8 \/var\/www\/html\/pr\/app\/code\/Magento\/Eav\/Model\/Entity\/Collection\/AbstractCollection.php(920): Magento\\CatalogSearch\\Model\\ResourceModel\\Fulltext\\Collection->_renderFilters()\n#9 \/var\/www\/html\/pr\/app\/code\/Magento\/Catalog\/Model\/ResourceModel\/Product\/Collection.php(790): Magento\\Eav\\Model\\Entity\\Collection\\AbstractCollection->load(false, false)\n#10 \/var\/www\/html\/pr\/lib\/internal\/Magento\/Framework\/Interception\/Interceptor.php(58): Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection->load(false, false)\n#11 \/var\/www\/html\/pr\/lib\/internal\/Magento\/Framework\/Interception\/Interceptor.php(138): Magento\\CatalogSearch\\Model\\ResourceModel\\Fulltext\\Collection\\Interceptor->___callParent('load', Array)\n#12 \/var\/www\/html\/pr\/lib\/internal\/Magento\/Framework\/Interception\/Interceptor.php(153): Magento\\CatalogSearch\\Model\\ResourceModel\\Fulltext\\Collection\\Interceptor->Magento\\Framework\\Interception\\{closure}()\n#13 \/var\/www\/html\/pr\/generated\/code\/Magento\/CatalogSearch\/Model\/ResourceModel\/Fulltext\/Collection\/Interceptor.php(325): Magento\\CatalogSearch\\Model\\ResourceModel\\Fulltext\\Collection\\Interceptor->___callPlugins('load', Array, Array)\n#14 \/var\/www\/html\/pr\/app\/code\/Magento\/Review\/Observer\/CatalogBlockProductCollectionBeforeToHtmlObserver.php(38): Magento\\CatalogSearch\\Model\\ResourceModel\\Fulltext\\Collection\\Interceptor->load()\n#15 \/var\/www\/html\/pr\/lib\/internal\/Magento\/Framework\/Event\/Invoker\/InvokerDefault.php(72): Magento\\Review\\Observer\\CatalogBlockProductCollectionBeforeToHtmlObserver->execute(Object(Magento\\Framework\\Event\\Observer))\n#16 \/var\/www\/html\/pr\/lib\/internal\/Magento\/Framework\/Event\/Invoker\/InvokerDefault.php(60): Magento\\Framework\\Event\\Invoker\\InvokerDefault->_callObserverMethod(Object(Magento\\Review\\Observer\\CatalogBlockProductCollectionBeforeToHtmlObserver), Object(Magento\\Framework\\Event\\Observer))\n#17 \/var\/www\/html\/pr\/lib\/internal\/Magento\/Framework\/Event\/Manager.php(66): Magento\\Framework\\Event\\Invoker\\InvokerDefault->dispatch(Array, Object(Magento\\Framework\\Event\\Observer))\n#18 \/var\/www\/html\/pr\/generated\/code\/Magento\/Framework\/Event\/Manager\/Proxy.php(95): Magento\\Framework\\Event\\Manager->dispatch('catalog_block_p...', Array)\n#19 \/var\/www\/html\/pr\/app\/code\/Magento\/Catalog\/Block\/Product\/ListProduct.php(471): Magento\\Framework\\Event\\Manager\\Proxy->dispatch('catalog_block_p...', Array)\n#20 \/var\/www\/html\/pr\/app\/code\/Magento\/Catalog\/Block\/Product\/ListProduct.php(116): Magento\\Catalog\\Block\\Product\\ListProduct->initializeProductCollection()\n#21 \/var\/www\/html\/pr\/app\/code\/Magento\/Catalog\/Block\/Product\/ListProduct.php(348): Magento\\Catalog\\Block\\Product\\ListProduct->_getProductCollection()\n#22 \/var\/www\/html\/pr\/generated\/code\/Magento\/Catalog\/Block\/Product\/ListProduct\/Interceptor.php(154): Magento\\Catalog\\Block\\Product\\ListProduct->getIdentities()\n#23 \/var\/www\/html\/pr\/app\/code\/Magento\/PageCache\/Model\/Layout\/LayoutPlugin.php(71): Magento\\Catalog\\Block\\Product\\ListProduct\\Interceptor->getIdentities()\n#24 \/var\/www\/html\/pr\/lib\/internal\/Magento\/Framework\/Interception\/Interceptor.php(146): Magento\\PageCache\\Model\\Layout\\LayoutPlugin->afterGetOutput(Object(Magento\\Framework\\View\\Layout\\Interceptor), '\\n    <script ty...')\n#25 \/var\/www\/html\/pr\/lib\/internal\/Magento\/Framework\/Interception\/Interceptor.php(153): Magento\\Framework\\View\\Layout\\Interceptor->Magento\\Framework\\Interception\\{closure}()\n#26 \/var\/www\/html\/pr\/generated\/code\/Magento\/Framework\/View\/Layout\/Interceptor.php(494): Magento\\Framework\\View\\Layout\\Interceptor->___callPlugins('getOutput', Array, Array)\n#27 \/var\/www\/html\/pr\/lib\/internal\/Magento\/Framework\/View\/Result\/Page.php(257): Magento\\Framework\\View\\Layout\\Interceptor->getOutput()\n#28 \/var\/www\/html\/pr\/lib\/internal\/Magento\/Framework\/View\/Result\/Layout.php(170): Magento\\Framework\\View\\Result\\Page->render(Object(Magento\\Framework\\App\\Response\\Http\\Interceptor))\n#29 \/var\/www\/html\/pr\/lib\/internal\/Magento\/Framework\/Interception\/Interceptor.php(58): Magento\\Framework\\View\\Result\\Layout->renderResult(Object(Magento\\Framework\\App\\Response\\Http\\Interceptor))\n#30 \/var\/www\/html\/pr\/lib\/internal\/Magento\/Framework\/Interception\/Interceptor.php(138): Magento\\Framework\\View\\Result\\Page\\Interceptor->___callParent('renderResult', Array)\n#31 \/var\/www\/html\/pr\/lib\/internal\/Magento\/Framework\/Interception\/Interceptor.php(153): Magento\\Framework\\View\\Result\\Page\\Interceptor->Magento\\Framework\\Interception\\{closure}(Object(Magento\\Framework\\App\\Response\\Http\\Interceptor))\n#32 \/var\/www\/html\/pr\/generated\/code\/Magento\/Framework\/View\/Result\/Page\/Interceptor.php(130): Magento\\Framework\\View\\Result\\Page\\Interceptor->___callPlugins('renderResult', Array, Array)\n#33 \/var\/www\/html\/pr\/lib\/internal\/Magento\/Framework\/App\/Http.php(139): Magento\\Framework\\View\\Result\\Page\\Interceptor->renderResult(Object(Magento\\Framework\\App\\Response\\Http\\Interceptor))\n#34 \/var\/www\/html\/pr\/generated\/code\/Magento\/Framework\/App\/Http\/Interceptor.php(24): Magento\\Framework\\App\\Http->launch()\n#35 \/var\/www\/html\/pr\/lib\/internal\/Magento\/Framework\/App\/Bootstrap.php(257): Magento\\Framework\\App\\Http\\Interceptor->launch()\n#36 \/var\/www\/html\/pr\/index.php(39): Magento\\Framework\\App\\Bootstrap->run(Object(Magento\\Framework\\App\\Http\\Interceptor))\n#37 {main}","url":"\/category-1.html","script_name":"\/index.php"}

I was not able to reproduce the issue on latest 2.2-develop and latest available ElasticSearch 5+, because ElasticSearch was not in the list of available search providers.

screenshot_20181109_161614

Additional information:

"version" : {
    "number" : "5.6.13",
    "build_hash" : "4d5320b",
    "build_date" : "2018-10-30T19:05:08.237Z",
    "build_snapshot" : false,
    "lucene_version" : "6.6.1"
  }

@xi-ao, please specify your version of ElasticSearch. I check the version by executing this request:

curl -X GET "localhost:9200/"

Hi @sdzhepa , Indeed im unable to reproduce the error. The bug seems to be absent from current 2.3-develop. Tested on elasticsearch 5.6.1 with magento backend option elasticsearch 5.0+

{
  "name" : "kjc7x2r",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "wlx_aKCYRtSBNjSOjGumfQ",
  "version" : {
    "number" : "5.6.1",
    "build_hash" : "667b497",
    "build_date" : "2017-09-14T19:22:05.189Z",
    "build_snapshot" : false,
    "lucene_version" : "6.6.1"
  },
  "tagline" : "You Know, for Search"
}

Also tested on elasticsearch 6.X, with magento option elasticsearch 6.0+ no issues there as well.

Side note: I encountered the error on 2.3.0 with elasticsearch 5.0. (see @TomashKhamlai steps to reproduce the bug )

Regards.

I’ll help with the documentation updates.

@TomashKhamlai Thank you for verifying the issue. Based on the provided information internal tickets MAGETWO-96261 were created