GLQL pagination returns empty results after first page when using Advanced Search

Summary

When using GLQL with Advanced Search (Elasticsearch) enabled, pagination fails to return results beyond the first page. Clicking "Load more" returns an empty result set even when more matching items exist.

Steps to reproduce

  1. Enable Advanced Search (Elasticsearch) integration
  2. Create a project with multiple work items (more than the page limit)
  3. Ensure work items have sortable field values that span multiple pages
  4. Navigate to the project's work items page
  5. Execute a GLQL query with sorting and a small page limit:
    display: table
    fields: title, milestone
    limit: 3
    query: project = "your-project" AND type = issue
    sort: created_at asc
  6. Wait for the first page to load (should show first 3 items)
  7. Click the "Load more" button to fetch the next page

What is the current bug behavior?

When clicking "Load more":

  • An empty result set is returned (nodes: [])
  • hasNextPage is false
  • count is 0
  • No additional items are loaded

The GraphQL request is sent with the correct after cursor parameter, and the Elasticsearch query is generated with pagination filters, but no results match the filter criteria.

What is the expected correct behavior?

Clicking "Load more" should:

  1. Use the cursor from the previous page to fetch the next set of results
  2. Return the next page of items that match the query
  3. Continue until all matching items have been retrieved
  4. Allow users to paginate through all available results

Example

Test scenario:

  • Project with 10 work items (IDs 1-10)
  • GLQL query with limit: 3 and sort: created_at asc

Expected:

  • Page 1: Items 1, 2, 3
  • Page 2 (after "Load more"): Items 4, 5, 6
  • Page 3 (after "Load more"): Items 7, 8, 9
  • Page 4 (after "Load more"): Item 10

Actual:

  • Page 1: Items 1, 2, 3
  • Page 2 (after "Load more"): Empty (0 items)

Additional context

  • The issue only occurs with Advanced Search (Elasticsearch) integration
  • Database-only work item queries work correctly
  • The GraphQL API correctly returns hasNextPage: true on the first page
  • The cursor value is correctly encoded and sent in the second request
  • Elasticsearch queries show pagination filters are being applied

Environment

  • GitLab version: 18.7.0-pre (likely affects earlier versions)
  • Feature flags: glql_es_integration enabled
  • Advanced Search: Enabled with Elasticsearch

This issue was discovered while testing GLQL functionality with Advanced Search integration.

Edited by Dmitry Gruzd