Skip to content

Negative ?p= query string causes ElasticSearch exception #40079

@lbajsarowicz

Description

@lbajsarowicz

Preconditions and environment

  • Magento 2.4.7-p6
  • ElasticSearch 8

Steps to reproduce

  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 )
  2. Change ?p=2 to ?p=-2

Expected result

  1. Expected to hit HTTP 302 redirect to 1st page of results,
  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)

Actual result

  1. "We can't find products matching the selection" on the storefront
  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 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
    

Additional information

No response

Release note

No response

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: CatalogComponent: CatalogIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.Reported on 2.4.7-p6Indicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branch

    Type

    No type

    Projects

    Status

    Ready for Development

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions