Skip to content

Conversation

@shmVan
Copy link
Contributor

@shmVan shmVan commented Jan 9, 2026

Description (*)

Problem: The quantity_and_stock_status attribute with "Use in Layered Navigation" enabled did not appear in filters after reindexing.

Root Cause: The attribute was in the excluded attributes list ($defaultExcludedAttributes) in the ProductDataMapper class, which is responsible for indexing data in Elasticsearch/OpenSearch. As a result:

  1. The attribute was NOT indexed in search engine documents
  2. getFacetedData() returned an empty array
  3. The filter was created but was empty (Items count: 0)

Solution: Removed 'quantity_and_stock_status' from the $defaultExcludedAttributes array in the file:

  • app/code/Magento/Elasticsearch/Model/Adapter/BatchDataMapper/ProductDataMapper.php:71

Verification: After reindexing, the filter now works and displays both options:

  • In Stock (788 products)
  • Out of Stock (1 product)

Why are other system attributes indexed but not this one?
Because quantity_and_stock_status is a special deprecated attribute that Magento explicitly excluded from indexing back in 2017 (when this file was created). Other system attributes (like status, visibility, tax_class_id)
are not in this exclusion list, so they are indexed normally.

Related Pull Requests

Fixed Issues (if relevant)

  1. Fixes Filter By quantity_and_stock_status not working #33453

Manual testing scenarios (*)

  1. Magento 2 with OpenSearch/Elasticsearch configured as search engine.
  2. At least one product category with products
  3. Some products should be "In Stock", some "Out of Stock"
  4. Navigate to Stores > Attributes > Product
  5. . Find and edit quantity_and_stock_status attribute
  6. Set Use in Layered Navigation = Filterable (with results)
  7. Save attribute
  8. Run reindex: bin/magento indexer:reindex catalogsearch_fulltext
  9. Navigate to category page on storefront
  10. Expected result : Quantity filter is visible in layered navigation

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

- The attribute was in the excluded attributes list ($defaultExcludedAttributes) in the ProductDataMapper class, which is responsible for indexing data in Elasticsearch/OpenSearch
@m2-assistant
Copy link

m2-assistant bot commented Jan 9, 2026

Hi @shmVan. Thank you for your contribution!
Here are some useful tips on how you can test your changes using Magento test environment.
❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names.

Allowed build names are:
  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here
ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.


For more details, review the Code Contributions documentation.
Join Magento Community Engineering Slack and ask your questions in #github channel.

@shmVan
Copy link
Contributor Author

shmVan commented Jan 9, 2026

@magento run all tests

@engcom-Hotel
Copy link
Contributor

@magento run all tests

@engcom-Hotel
Copy link
Contributor

@magento run Database Compare, Unit Tests

Copy link
Contributor

@engcom-Hotel engcom-Hotel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @shmVan,

Thank you for the contribution!

Can you please help us with the below questions regarding this PR:

  1. This attribute isn’t designed for searching, please refer to the below file. The attribute is explicitly configured as not searchable and not filterable. Why we are including this attribute in the search index?
  2. Have you checked this change with Multi-Source Inventory (MSI) which handles stock differently?
  3. What is the expected index size increase?

Also please cover the test with some automated test in accordance to the DOD.

Thank you

'media_gallery',
'tier_price',
'quantity_and_stock_status',
'media_gallery',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this duplicate attribute from here?

@engcom-Hotel engcom-Hotel moved this from Review in Progress to Changes Requested in Community Dashboard Jan 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: needs update Project: Community Picked PRs upvoted by the community

Projects

Status: Changes Requested

Development

Successfully merging this pull request may close these issues.

Filter By quantity_and_stock_status not working

3 participants