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

Bad SQL query to init EAV attributes #2769

Closed
odi-um opened this issue Nov 4, 2022 · 4 comments
Closed

Bad SQL query to init EAV attributes #2769

odi-um opened this issue Nov 4, 2022 · 4 comments
Assignees
Labels

Comments

@odi-um
Copy link

odi-um commented Nov 4, 2022

Indexer fails to index any product. Elasticsearch throws numerous errors like

[2022-11-02T21:28:12.551967+00:00] report.ERROR: Bulk index operation failed 1 times in index gc235_saaf_catalog_product_20221102_212751 for type _doc. Error (mapper_parsing_exception) : failed to parse field [status] of type [boolean] in document with id '20874'. Preview of field's value: '1'. Failed doc ids sample : 20874. [] []

these errors generated for every product.

Preconditions

Magento Version : Commerce 2.4.5

ElasticSuite Version : 2.10.12

Third party modules : Plumrocket GDPR

Steps to reproduce

Install any custom extensions which adds its own eav entity type and attributes with same codes as we have for product but with different type. For example products status attribute treated by ElasticSuite as int. On other hand "Display Checkbox" attribute from Plumrocket GDPR extension has same code status but source model is Magento\Eav\Model\Entity\Attribute\Source\Boolean so it is treated as a boolean.

Expected result

  1. product indexing works

Actual result

  1. product indexing does not work
  2. Elasticsearch throws errors
    Error (mapper_parsing_exception) : failed to parse field [status] of type [boolean] in document with id '20874'. Preview of field's value: '1'. Failed doc ids sample : 20874.

Problem in how ElasticSuite generates query to fetch all attribute for index. Root cause is in
\Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Indexer\Fulltext\Datasource\AttributeData::addIndexedFilterToAttributeCollection method when we add OR condition for status and sku attribute code. Resulting query looks like

SELECT
    `main_table`.`entity_type_id`,
    `main_table`.`attribute_code`,
    `main_table`.`attribute_model`,
    `main_table`.`backend_model`,
    `main_table`.`backend_type`,
    `main_table`.`backend_table`,
    `main_table`.`frontend_model`,
    `main_table`.`frontend_input`,
    `main_table`.`frontend_label`,
    `main_table`.`frontend_class`,
    `main_table`.`source_model`,
    `main_table`.`is_required`,
    `main_table`.`is_user_defined`,
    `main_table`.`default_value`,
    `main_table`.`is_unique`,
    `main_table`.`note`,
    `additional_table`.*
FROM
    `eav_attribute` AS `main_table`
    INNER JOIN `catalog_eav_attribute` AS `additional_table` ON additional_table.attribute_id = main_table.attribute_id
WHERE (main_table.entity_type_id = 4)
    AND(is_searchable = 1
        OR is_visible_in_advanced_search = 1
        OR is_filterable > 0
        OR is_filterable_in_search = 1
        OR is_used_for_promo_rules = 1
        OR used_for_sort_by = 1
       ) OR(attribute_code IN('status', 'sku'))

and in result we try to index status attributes from different entity types.

entity_type_id attribute_code source_model
4 status Magento\Catalog\Model\Product\Attribute\Source\Status
9 status Magento\Rma\Model\Item\Attribute\Source\Status
12 status Magento\Eav\Model\Entity\Attribute\Source\Boolean
@vahonc
Copy link
Collaborator

vahonc commented Nov 8, 2022

Hi Dmytro!

We need more details about your Elasticsearch server like whether it's Elasticsearch or Opensearch, which version you are using, and where it is hosted (AWS, Magento Cloud, etc).

It seems that your issue could be linked to the mapping settings, including a strict type for true, on the side of Elasticsearch.

BR,
Vadym

@odi-um
Copy link
Author

odi-um commented Nov 14, 2022

hi @vahonc,

We are using elasticsearch version 7.6.0. Project hosted on hypernode. We were able to reproduce issue on every dev instance we had within our team.

May be there is a strict mapping setting. But bad query generated and this is not affected by elasticsearch settings in any way.

@romainruaud
Copy link
Collaborator

For me the OR(attribute_code IN('status', 'sku')) should be something like OR(attribute_code IN('status', 'sku') AND entity_type_id=4) to be sure we are fetching the "status" attribute that belongs to the "product" entity.

@romainruaud romainruaud assigned vahonc and unassigned odi-um Nov 14, 2022
vahonc added a commit to vahonc/elasticsuite that referenced this issue Nov 21, 2022
@vahonc
Copy link
Collaborator

vahonc commented Nov 23, 2022

@odi-um,

Could you check if my fix solved your problem?

BR,
Vadym

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