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
- Enable the feature flag for the user you are logging into gdk with:
Feature.enable(:search_blobs_language_aggregation, user)
- Run a code search (global, group or project level - it does not matter which)
- 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) - Open the
SearchController
in your favorite editor and addbinding.pry
after the@aggregations
variable is defined
@aggregations = @search_service.search_aggregations
binding.pry
- Run
gdk thin
on the command line - Run the same code search and verify the
@aggregations
variable returns aggregations - Run another type of search (anything but code) and verify the
@aggregations
variable is set to empty array - 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.
-
I have evaluated the MR acceptance checklist for this MR.