{"data":{"id":"magento2-40080","source":"github-pr","sourceRef":"magento/magento2#40080","title":"Negative `?p=` query string causes ElasticSearch exception","pr":{"number":40080,"url":"https://github.com/magento/magento2/pull/40080","author":"lbajsarowicz","mergedAt":"2025-11-19T17:37:53Z","mergeCommit":"d2fd820bb6e4f3d55d16d90416ded3201bba9a00","headCommit":"110579b6698d6a280b12636bcb8307d59e60ffdc","baseRef":"2.4-develop","diffSha256":"25102e844676624f6d19d71c8906b71bea34198b17f6f8bac49c1b13917f5857"},"issues":[{"number":40079,"url":"https://github.com/magento/magento2/issues/40079","title":"Negative `?p=` query string causes ElasticSearch exception","labels":["Area: Catalog","Component: Catalog","Issue: Confirmed","Priority: P2","Progress: done","Reported on 2.4.7-p6","Reproduced on 2.4.x"],"kind":"human"}],"fixedIn":"2.4.9","containingTags":["2.4.9"],"reportedOn":"2.4.7-p6","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":"conflict","2.4.8-p1":"conflict","2.4.8-p2":"conflict","2.4.8-p3":"conflict","2.4.8-p4":"conflict","2.4.8-p5":"conflict","2.4.9":"conflict"},"affectedVersions":[],"components":["magento/module-catalog","magento/module-catalog-search"],"files":[{"path":"app/code/Magento/Catalog/Controller/Category/View.php","change":"modified","package":"magento/module-catalog"},{"path":"app/code/Magento/CatalogSearch/Controller/Result/Index.php","change":"modified","package":"magento/module-catalog-search"}],"stripped":{"tests":["app/code/Magento/Catalog/Test/Mftf/Test/StorefrontPaginationResetOnNegativePageNumberTest.xml","app/code/Magento/CatalogSearch/Test/Mftf/Test/CatalogSearchWithNegativePageNumberTest.xml"],"docs":[],"outsideCode":[]},"linesChanged":258,"mergeBatched":false,"excluded":null,"sections":{"description":"1. \"We can't find products matching the selection\" on the storefront\n2. Exception log\n    ```\n    [2025-07-18T08:51:57.205541+00:00] .CRITICAL: Elasticsearch\\Common\\Exceptions\\BadRequest400Exception: {\"error\":{\"root_cause\":[{\"type\":\"illegal_argument_exception\",\"reason\":\"numHits must be > 0; please use TotalHitCountCollector if you just need the total hit count\"}],\"type\":\"search_phase_execution_exception\",\"reason\":\"all shards failed\",\"phase\":\"query\",\"grouped\":true,\"failed_shards\":[{\"shard\":0,\"index\":\"local__product_1_v3\",\"node\":\"6QGS43UJRPuMWbWoEdD4vA\",\"reason\":{\"type\":\"illegal_argument_exception\",\"reason\":\"numHits must be > 0; please use TotalHitCountCollector if you just need the total hit count\"}}],\"caused_by\":{\"type\":\"illegal_argument_exception\",\"reason\":\"numHits must be > 0; please use TotalHitCountCollector if you just need the total hit count\",\"caused_by\":{\"type\":\"illegal_argument_exception\",\"reason\":\"numHits must be > 0; please use TotalHitCountCollector if you just need the total hit count\"}}},\"status\":400} in /var/www/html/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php:693\n    ```","stepsToReproduce":"1. Navigate to Product Category (e.g. https://magento2-demo.magebit.com/collections/yoga-new.html ), move to 2nd page ( https://magento2-demo.magebit.com/collections/yoga-new.html?p=2 )\n2. Change `?p=2` to `?p=-2`","expectedResult":"1. Expected to hit HTTP 302 redirect to 1st page of results,\n2. Expected to **not** see the Exception Log entry related to the occurrence (it's not application error, but User Input is out of supported range)","actualResult":"1. \"We can't find products matching the selection\" on the storefront\n2. Exception log\n    ```\n    [2025-07-18T08:51:57.205541+00:00] .CRITICAL: Elasticsearch\\Common\\Exceptions\\BadRequest400Exception: {\"error\":{\"root_cause\":[{\"type\":\"illegal_argument_exception\",\"reason\":\"numHits must be > 0; please use TotalHitCountCollector if you just need the total hit count\"}],\"type\":\"search_phase_execution_exception\",\"reason\":\"all shards failed\",\"phase\":\"query\",\"grouped\":true,\"failed_shards\":[{\"shard\":0,\"index\":\"local__product_1_v3\",\"node\":\"6QGS43UJRPuMWbWoEdD4vA\",\"reason\":{\"type\":\"illegal_argument_exception\",\"reason\":\"numHits must be > 0; please use TotalHitCountCollector if you just need the total hit count\"}}],\"caused_by\":{\"type\":\"illegal_argument_exception\",\"reason\":\"numHits must be > 0; please use TotalHitCountCollector if you just need the total hit count\",\"caused_by\":{\"type\":\"illegal_argument_exception\",\"reason\":\"numHits must be > 0; please use TotalHitCountCollector if you just need the total hit count\"}}},\"status\":400} in /var/www/html/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php:693\n    ```","source":"issue"},"signatures":["2. Expected to **not** see the Exception Log entry related to the occurrence (it's not application error, but User Input is out of supported range)","2. Exception log","[2025-07-18T08:51:57.205541+00:00] .CRITICAL: Elasticsearch\\Common\\Exceptions\\BadRequest400Exception: {\"error\":{\"root_cause\":[{\"type\":\"illegal_argument_exception\",\"reason\":\"numHits must be > 0; please"],"labels":{"area":["Catalog"],"component":["Catalog"],"priority":"P2","severity":null,"reportedOn":["2.4.7-p6"]},"categories":["Catalog/Product"],"triage":{"model":"@cf/cloudflare/clef","requestHash":"30e8658bb3b5e3987fa520d0d6ea52c323439e78ae92cc00014e80fb0712c2af","isBugfix":0.9782,"changeKind":{"choice":"bugfix","probabilities":{"bugfix":0.9532,"feature":0.0094,"refactor":0.0185,"tests_only":0.01,"docs_only":0.004,"dependency":0.0049},"confidence":0.8911},"scope":{"score":1.2205,"probabilities":{"0":0.1645,"1":0.4505,"2":0.385},"confidence":0.0674},"risk":{"score":0.6725,"probabilities":{"0":0.4309,"1":0.4658,"2":0.1033},"confidence":0.12},"area":{"choice":"catalog","probabilities":{"catalog":0.8721,"checkout":0.0113,"customer":0.0098,"admin":0.0194,"graphql_api":0.0088,"framework":0.0224,"frontend":0.0324,"other":0.0238},"confidence":0.7295},"securityRelevant":0.0102,"reportedVersion":{"choice":"2.4.7-p6","probabilities":{"2.4.0":0.0018,"2.4.0-p1":0.0023,"2.4.1":0.002,"2.4.1-p1":0.0025,"2.4.2":0.0019,"2.4.2-p1":0.0024,"2.4.2-p2":0.0023,"2.4.3":0.002,"2.4.3-p1":0.0025,"2.4.3-p2":0.0028,"2.4.3-p3":0.0025,"2.4.4":0.0021,"2.4.4-p1":0.0024,"2.4.4-p10":0.0029,"2.4.4-p11":0.0037,"2.4.4-p12":0.0034,"2.4.4-p13":0.0036,"2.4.4-p14":0.0034,"2.4.4-p15":0.003,"2.4.4-p16":0.0031,"2.4.4-p17":0.0032,"2.4.4-p18":0.0029,"2.4.4-p2":0.0021,"2.4.4-p3":0.0023,"2.4.4-p4":0.0023,"2.4.4-p5":0.0028,"2.4.4-p6":0.0043,"2.4.4-p7":0.0025,"2.4.4-p8":0.0027,"2.4.4-p9":0.0024,"2.4.5":0.0023,"2.4.5-p1":0.0026,"2.4.5-p10":0.0028,"2.4.5-p11":0.0032,"2.4.5-p12":0.0042,"2.4.5-p13":0.0034,"2.4.5-p14":0.0039,"2.4.5-p15":0.0033,"2.4.5-p16":0.0031,"2.4.5-p17":0.0028,"2.4.5-p2":0.0023,"2.4.5-p3":0.0025,"2.4.5-p4":0.0026,"2.4.5-p5":0.0032,"2.4.5-p6":0.0048,"2.4.5-p7":0.003,"2.4.5-p8":0.0029,"2.4.5-p9":0.0025,"2.4.6":0.0065,"2.4.6-p1":0.0042,"2.4.6-p10":0.0045,"2.4.6-p11":0.0051,"2.4.6-p12":0.0056,"2.4.6-p13":0.0044,"2.4.6-p14":0.0048,"2.4.6-p15":0.0045,"2.4.6-p2":0.0027,"2.4.6-p3":0.0033,"2.4.6-p4":0.0047,"2.4.6-p5":0.0049,"2.4.6-p6":0.0055,"2.4.6-p7":0.0045,"2.4.6-p8":0.0041,"2.4.6-p9":0.0032,"2.4.7":0.0675,"2.4.7-p1":0.0034,"2.4.7-p10":0.0034,"2.4.7-p2":0.0025,"2.4.7-p3":0.0042,"2.4.7-p4":0.0054,"2.4.7-p5":0.0115,"2.4.7-p6":0.5985,"2.4.7-p7":0.0202,"2.4.7-p8":0.0118,"2.4.7-p9":0.0106,"2.4.8":0.0072,"2.4.8-p1":0.0072,"2.4.8-p2":0.007,"2.4.8-p3":0.0091,"2.4.8-p4":0.008,"2.4.8-p5":0.0068,"2.4.9":0.0051,"unspecified":0.0026},"confidence":0.357},"backportWorthy":{"score":1.6194,"probabilities":{"0":0.068,"1":0.2447,"2":0.6873},"confidence":0.3054}},"curated":{"title":"Fixes exceptions for a negative ?p= value on category and search result pages","description":"A negative ?p= value in the category pagination results in an Elasticsearch exception and \"We can't find products matching the selection\". The Category View controller now sets a 301 redirect to the category URL, and the CatalogSearch Result Index controller sets a redirect to the URL without the p value.","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-40080 details"}