Skip to content

Expose blob search aggregations to SearchController

What does this MR do and why?

Related to #342643 (closed)

This MR passes Elasticsearch aggregations up to the SearchController if available.

Specs were added at each level and include the search_blobs_language_aggregation feature flag (which is currently disabled by default and pending rollout via: #342621 (closed))

Since Elasticseasrch aggregations can have multiple facets, I chose to keep the data format pretty close to what Elasticsearch returns. Each bucket contain a key which could contain multiple values (but for blob.language only contains one), and a count which is the document count for that facet.

Example format:

#<Gitlab::Search::Aggregation:0x00007fbedfc788f0
 @buckets=
  [{:key=>{"language"=>"C"}, :count=>142},
   {:key=>{"language"=>"C++"}, :count=>6},
   {:key=>{"language"=>"CSS"}, :count=>1},
   {:key=>{"language"=>"CSV"}, :count=>10},
   {:key=>{"language"=>"Dockerfile"}, :count=>2},
   {:key=>{"language"=>"Gettext Catalog"}, :count=>108},
   {:key=>{"language"=>"HTML"}, :count=>9},
   {:key=>{"language"=>"HTML+ERB"}, :count=>2},
   {:key=>{"language"=>"Haml"}, :count=>36},
   {:key=>{"language"=>"JSON"}, :count=>74}],
 @name="language">

Screenshots or screen recordings

N/A

How to set up and validate locally

Note: you must have your GDK setup for Elasticsearch and enabled Advanced Search indexing/search features

  1. Enable the feature flag for the user you are logging into gdk with: Feature.enable(:search_blobs_language_aggregation, user)
  2. Run a code search (global, group or project level - it does not matter which)
  3. Verify that the aggregations show up in the performance bar for the blob search (what you are looking for is the aggs section in the JSON request to Elasticsearch, near the bottom)
  4. Open the SearchController in your favorite editor and add binding.pry after the @aggregations variable is defined
    @aggregations = @search_service.search_aggregations
    binding.pry
  1. Run gdk thin on the command line
  2. Run the same code search and verify the @aggregations variable returns aggregations
  3. Run another type of search (anything but code) and verify the @aggregations variable is set to empty array
  4. Verify that the aggregations do not show up in the performance bar for the blob count call (what you are looking for is the aggs section in the JSON request to Elasticsearch, near the bottom)

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Terri Chu

Merge request reports

Loading