Skip to content

Advanced Search: more efficient user search

Description

The following error appears when using autocomplete suggestions.

  "exception.message": "[400] {\"error\":{\"root_cause\":[{\"type\":\"too_many_clauses\",\"reason\":\"too_many_clauses: maxClauseCount is set to 1024\"}],\"type\":\"search_phase_execution_exception\",\"reason\":\"all shards failed\",\"phase\":\"query\",\"grouped\":true,\"failed_shards\":[{\"shard\":0,\"index\":\"gitlab-production-users-20250326-1925-reindex-11-0\",\"node\":\"_iueBarzSVSe6RsBg3WlfQ\",\"reason\":{\"type\":\"query_shard_exception\",\"reason\":\"failed to create query: maxClauseCount is set to 1024\",\"index\":\"gitlab-production-users-20250326-1925-reindex-11-0\",\"index_uuid\":\"FUVAPQkFTsaPDqTTbHIh_A\",\"caused_by\":{\"type\":\"too_many_clauses\",\"reason\":\"too_many_clauses: maxClauseCount is set to 1024\"}}}],\"caused_by\":{\"type\":\"too_many_clauses\",\"reason\":\"too_many_clauses: maxClauseCount is set to 1024\"}},\"status\":400}",

If the current user is a member of many projects/groups, this can happen when filtering for users that the current user is allowed to see.

Background

https://gitlab.com/gitlab-com/request-for-help/-/issues/2619 (internal)

Proposal

When adding the filters for projects the current_user has access to, don't use a prefix query per project but rather a single terms query containing all the projects.

Changes required:

  1. Build a terms query using the authorized projects here instead of passing them to Search::Elastic::Filters.by_traversal_ids
  2. Put this change behind a feature flag
  3. Tests

Workaround

Increase the Elasticsearch setting to a higher value, e.g. 2048.

Edited by Vlad Mihai