{"data":{"id":"magento2-36900","source":"github-pr","sourceRef":"magento/magento2#36900","title":"Elastic Search interferes with the default sort order of products (changing newest first to oldest first)","pr":{"number":36900,"url":"https://github.com/magento/magento2/pull/36900","author":"rogerdz","mergedAt":"2025-11-19T17:37:53Z","mergeCommit":"5b9944dac0f032ce812873e5133aabaa4d57203f","headCommit":"343d04a260998ed35546f0f399dabd19e0d991bb","baseRef":"2.4-develop","diffSha256":"3279b477cd73129dbc5e731de147f7bcbfc8889022780ed336c82e12128b0ef9"},"issues":[{"number":31043,"url":"https://github.com/magento/magento2/issues/31043","title":"Elastic Search interferes with the default sort order of products (changing newest first to oldest first)","labels":["Area: Catalog","Component: Catalog","Issue: Confirmed","Priority: P2","Progress: PR in progress","Progress: done","Reported on 2.3.5-p1","Reproduced on 2.4.x"],"kind":"human"}],"fixedIn":"2.4.9","containingTags":["2.4.9"],"reportedOn":"2.3.5-p1","codeMatch":{"2.4.6":"conflict","2.4.6-p1":"conflict","2.4.6-p2":"conflict","2.4.6-p3":"conflict","2.4.6-p4":"conflict","2.4.6-p5":"conflict","2.4.6-p6":"conflict","2.4.6-p7":"conflict","2.4.6-p8":"conflict","2.4.6-p9":"conflict","2.4.6-p10":"conflict","2.4.6-p11":"conflict","2.4.6-p12":"conflict","2.4.6-p13":"conflict","2.4.6-p14":"conflict","2.4.6-p15":"conflict","2.4.7":"conflict","2.4.7-p1":"conflict","2.4.7-p2":"conflict","2.4.7-p3":"conflict","2.4.7-p4":"conflict","2.4.7-p5":"conflict","2.4.7-p6":"conflict","2.4.7-p7":"conflict","2.4.7-p8":"conflict","2.4.7-p9":"conflict","2.4.7-p10":"conflict","2.4.8":"clean","2.4.8-p1":"clean","2.4.8-p2":"clean","2.4.8-p3":"clean","2.4.8-p4":"clean","2.4.8-p5":"clean","2.4.9":"conflict"},"affectedVersions":["2.4.8","2.4.8-p1","2.4.8-p2","2.4.8-p3","2.4.8-p4","2.4.8-p5"],"components":["magento/module-catalog","magento/module-catalog-search"],"files":[{"path":"app/code/Magento/Catalog/Model/Config/Source/SortOrder.php","change":"added","package":"magento/module-catalog"},{"path":"app/code/Magento/Catalog/etc/adminhtml/system.xml","change":"modified","package":"magento/module-catalog"},{"path":"app/code/Magento/Catalog/etc/config.xml","change":"modified","package":"magento/module-catalog"},{"path":"app/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext/Collection.php","change":"modified","package":"magento/module-catalog-search"}],"stripped":{"tests":["app/code/Magento/Catalog/Test/Mftf/Data/CatalogStorefrontConfigData.xml","app/code/Magento/Catalog/Test/Mftf/Test/StorefrontPaginationResetOnViewModeChangeTest.xml","app/code/Magento/Catalog/Test/Mftf/Test/StorefrontProductSortByPositionInDescOrderTest.xml","app/code/Magento/Catalog/Test/Mftf/Test/StorefrontPropertiesOfAProductAttributeTest.xml","app/code/Magento/CatalogSearch/Test/Mftf/Test/SearchEntityResultsTest/QuickSearchTwoProductsWithSameWeightTest.xml"],"docs":[],"outsideCode":[]},"linesChanged":43,"mergeBatched":false,"excluded":null,"sections":{"description":"1. The oldest products(with the lower entity_id) are shown first\n![image](https://user-images.githubusercontent.com/51681379/106890806-84bc8c00-66f2-11eb-8b31-d15f21fab822.png)\n2. The Order by for the SQL query for retrieving the products\n```\nSELECT `e`.*, `price_index`.`price`, `price_index`.`tax_class_id`, `price_index`.`final_price`, IF(price_index.tier_price IS NOT NULL, LEAST(price_index.min_price, price_index.tier_price), price_index.min_price) AS `minimal_price`, `price_index`.`min_price`, `price_index`.`max_price`, `price_index`.`tier_price`, IFNULL(review_summary.reviews_count, 0) AS `reviews_count`, IFNULL(review_summary.rating_summary, 0) AS `rating_summary`, `stock_status_index`.`stock_status` AS `is_salable` FROM `catalog_product_entity` AS `e`\n INNER JOIN `catalog_product_index_price` AS `price_index` ON price_index.entity_id = e.entity_id AND price_index.customer_group_id = 0 AND price_index.website_id = '1'\n LEFT JOIN `review_entity_summary` AS `review_summary` ON e.entity_id = review_summary.entity_pk_value AND review_summary.store_id = 1 AND review_summary.entity_type = (SELECT `review_entity`.`entity_id` FROM `review_entity` WHERE (entity_code = 'product'))\n INNER JOIN `cataloginventory_stock_status` AS `stock_status_index` ON e.entity_id = stock_status_index.product_id AND stock_status_index.website_id = 0 AND stock_status_index.stock_id = 1 WHERE (stock_status_index.stock_status = 1) AND (e.entity_id IN (1201, 1202, 1203)) ORDER BY FIELD(e.entity_id,1201,1202,1203)\n```","stepsToReproduce":"- Create a category in Magento with several products in it, all have the position in the category set to the value 1\n![image](https://user-images.githubusercontent.com/51681379/106890207-a9fcca80-66f1-11eb-8c0a-3b6f625e27d0.png)\n\n- Go to category page","expectedResult":"1. The newest products in the database (the one with the highest entity_id) are shown first\n![image](https://user-images.githubusercontent.com/51681379/106890774-7a9a8d80-66f2-11eb-8261-91c77a9001e9.png)\n2. The Order by for the SQL query for retrieving the products\n```\n SELECT `e`.*, `cat_index`.`position` AS `cat_index_position`, `price_index`.`price`, `price_index`.`tax_class_id`, `price_index`.`final_price`, IF(price_index.tier_price IS NOT NULL, LEAST(price_index.min_price, price_index.tier_price), price_index.min_price) AS `minimal_price`, `price_index`.`min_price`, `price_index`.`max_price`, `price_index`.`tier_price` FROM `catalog_product_entity` AS `e`\n INNER JOIN `catalog_category_product_index_store1` AS `cat_index` ON cat_index.product_id=e.entity_id AND cat_index.store_id=1 AND cat_index.visibility IN(2, 4) AND cat_index.category_id=33\n INNER JOIN `catalog_product_index_price` AS `price_index` ON price_index.entity_id = e.entity_id AND price_index.customer_group_id = 0 AND price_index.website_id = '1' ORDER BY `cat_index`.`position` asc, `e`.`entity_id` DESC\n```","actualResult":"1. The oldest products(with the lower entity_id) are shown first\n![image](https://user-images.githubusercontent.com/51681379/106890806-84bc8c00-66f2-11eb-8b31-d15f21fab822.png)\n2. The Order by for the SQL query for retrieving the products\n```\nSELECT `e`.*, `price_index`.`price`, `price_index`.`tax_class_id`, `price_index`.`final_price`, IF(price_index.tier_price IS NOT NULL, LEAST(price_index.min_price, price_index.tier_price), price_index.min_price) AS `minimal_price`, `price_index`.`min_price`, `price_index`.`max_price`, `price_index`.`tier_price`, IFNULL(review_summary.reviews_count, 0) AS `reviews_count`, IFNULL(review_summary.rating_summary, 0) AS `rating_summary`, `stock_status_index`.`stock_status` AS `is_salable` FROM `catalog_product_entity` AS `e`\n INNER JOIN `catalog_product_index_price` AS `price_index` ON price_index.entity_id = e.entity_id AND price_index.customer_group_id = 0 AND price_index.website_id = '1'\n LEFT JOIN `review_entity_summary` AS `review_summary` ON e.entity_id = review_summary.entity_pk_value AND review_summary.store_id = 1 AND review_summary.entity_type = (SELECT `review_entity`.`entity_id` FROM `review_entity` WHERE (entity_code = 'product'))\n INNER JOIN `cataloginventory_stock_status` AS `stock_status_index` ON e.entity_id = stock_status_index.product_id AND stock_status_index.website_id = 0 AND stock_status_index.stock_id = 1 WHERE (stock_status_index.stock_status = 1) AND (e.entity_id IN (1201, 1202, 1203)) ORDER BY FIELD(e.entity_id,1201,1202,1203)\n```\n\n:warning: **Note**: In Magento 2.3.6 with `Search Engine=MySQL` the newest product in the database (the one with the highest entity_id) was shown first. With Magento 2.4-develop with `Search Engine= Elasticsearch 7` this behaviour changed. The oldest product is shown first, the newest last.\n\n---\nPlease provide [Severity](https://devdocs.magento.com/guides/v2.3/contributor-guide/contributing.html#backlog) assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.\n\n- [ ] Severity: **S0** _- Affects critical data or functionality and leaves users without workaround._\n- [ ] Severity: **S1** _- Affects critical data or functionality and forces users to employ a workaround._\n- [ ] Severity: **S2** _- Affects non-critical data or functionality and forces users to employ a workaround._\n- [ ] Severity: **S3** _- Affects non-critical data or functionality and does not force users to employ a workaround._\n- [ ] Severity: **S4** _- Affects aesthetics, professional look and feel, “quality” or “usability”._\n\nThe severity of this issue will differ between niches but for some businesses, this is quite critical. Like designer or boutique fashion retailers where the target audience frequent the website to view the latest items to hit the fashion lines etc.\n\n---\n\nI can't believe there are not more reports of this... I did [ask the question](https://magento.stackexchange.com/questions/326729/elastic-search-v7-changing-magento-default-product-sort-position-in-categories) on Magento Stack Exchange and it is passed by will hardly any views and zero interaction.\n\nI'm obviously assuming this is a bug and not meant to happen.","source":"issue"},"signatures":[],"labels":{"area":["Catalog"],"component":["Catalog"],"priority":"P2","severity":null,"reportedOn":["2.3.5-p1"]},"categories":["Catalog/Product"],"triage":{"model":"@cf/cloudflare/clef","requestHash":"c73e46d2a52dad9d055319a96efbd062cfd4d7decdcbcb48e401a5de9d78e00b","isBugfix":0.9336,"changeKind":{"choice":"bugfix","probabilities":{"bugfix":0.8426,"feature":0.1279,"refactor":0.0166,"tests_only":0.0084,"docs_only":0.002,"dependency":0.0025},"confidence":0.672},"scope":{"score":1.4912,"probabilities":{"0":0.1485,"1":0.2118,"2":0.6397},"confidence":0.2142},"risk":{"score":0.765,"probabilities":{"0":0.4049,"1":0.4252,"2":0.1699},"confidence":0.0604},"area":{"choice":"catalog","probabilities":{"catalog":0.79,"checkout":0.0087,"customer":0.0056,"admin":0.1103,"graphql_api":0.0067,"framework":0.0272,"frontend":0.0302,"other":0.0213},"confidence":0.5869},"securityRelevant":0.0073,"reportedVersion":{"choice":"unspecified","probabilities":{"2.4.0":0.0077,"2.4.0-p1":0.0082,"2.4.1":0.0126,"2.4.1-p1":0.0105,"2.4.2":0.0107,"2.4.2-p1":0.0142,"2.4.2-p2":0.0314,"2.4.3":0.0256,"2.4.3-p1":0.0304,"2.4.3-p2":0.0246,"2.4.3-p3":0.0145,"2.4.4":0.0147,"2.4.4-p1":0.0131,"2.4.4-p10":0.0051,"2.4.4-p11":0.0058,"2.4.4-p12":0.0054,"2.4.4-p13":0.0064,"2.4.4-p14":0.0066,"2.4.4-p15":0.005,"2.4.4-p16":0.005,"2.4.4-p17":0.0046,"2.4.4-p18":0.0043,"2.4.4-p2":0.0049,"2.4.4-p3":0.0053,"2.4.4-p4":0.0053,"2.4.4-p5":0.0075,"2.4.4-p6":0.0055,"2.4.4-p7":0.0051,"2.4.4-p8":0.0052,"2.4.4-p9":0.0037,"2.4.5":0.0111,"2.4.5-p1":0.0095,"2.4.5-p10":0.0038,"2.4.5-p11":0.0052,"2.4.5-p12":0.0052,"2.4.5-p13":0.0059,"2.4.5-p14":0.0044,"2.4.5-p15":0.0043,"2.4.5-p16":0.0047,"2.4.5-p17":0.0049,"2.4.5-p2":0.0042,"2.4.5-p3":0.0051,"2.4.5-p4":0.0078,"2.4.5-p5":0.0061,"2.4.5-p6":0.0063,"2.4.5-p7":0.0048,"2.4.5-p8":0.0045,"2.4.5-p9":0.0031,"2.4.6":0.0052,"2.4.6-p1":0.0049,"2.4.6-p10":0.0042,"2.4.6-p11":0.0054,"2.4.6-p12":0.0055,"2.4.6-p13":0.0063,"2.4.6-p14":0.0056,"2.4.6-p15":0.0048,"2.4.6-p2":0.0039,"2.4.6-p3":0.0054,"2.4.6-p4":0.007,"2.4.6-p5":0.0074,"2.4.6-p6":0.0057,"2.4.6-p7":0.0064,"2.4.6-p8":0.0047,"2.4.6-p9":0.003,"2.4.7":0.0047,"2.4.7-p1":0.0041,"2.4.7-p10":0.0047,"2.4.7-p2":0.0042,"2.4.7-p3":0.0073,"2.4.7-p4":0.0096,"2.4.7-p5":0.0076,"2.4.7-p6":0.0114,"2.4.7-p7":0.0089,"2.4.7-p8":0.0064,"2.4.7-p9":0.0036,"2.4.8":0.0046,"2.4.8-p1":0.004,"2.4.8-p2":0.0066,"2.4.8-p3":0.0087,"2.4.8-p4":0.0094,"2.4.8-p5":0.0082,"2.4.9":0.0105,"unspecified":0.3803},"confidence":0.1413},"backportWorthy":{"score":1.4149,"probabilities":{"0":0.1548,"1":0.2756,"2":0.5696},"confidence":0.1366}},"curated":{"title":"Fixes category pages showing the oldest products first, with a new sort config","description":"On a category page where products all have the same position, the CatalogSearch Fulltext Collection adds an entity_id ASC order, so the oldest products (with the lower entity_id) are shown first. A new store configuration, Product Listing Sort by Order (catalog/frontend/default_sort_by_order), now sets that order; the default is ASC, so newest first needs Descending.","categories":["Catalog/Product"],"author":"claude-code/opus-5.5","date":"2026-10-06","reviewedBy":null},"tests":null},"_documentation":"https://magento.watch/api","_description":"Upstream fix magento2-36900 details"}