From 8b4594f4619b70667cbcd2240cf696ecdc2d8813 Mon Sep 17 00:00:00 2001 From: Emma Date: Thu, 30 Apr 2026 15:00:48 +0100 Subject: [PATCH 1/5] Remove registry for document_series The "document_series" field has been renamed to "document_collections" [1]. There are no documents in elasticsearch with this field populated, so we no longer need the registry that expands the field. [1] https://github.com/alphagov/whitehall/pull/915 --- lib/search/presenters/entity_expander.rb | 1 - lib/search/registries.rb | 1 - lib/tasks/report_inconsistent_aggregate_values.rake | 1 - 3 files changed, 3 deletions(-) diff --git a/lib/search/presenters/entity_expander.rb b/lib/search/presenters/entity_expander.rb index 853c22541..80561ef6e 100644 --- a/lib/search/presenters/entity_expander.rb +++ b/lib/search/presenters/entity_expander.rb @@ -31,7 +31,6 @@ def initialize(registry_name, new_field_name: nil) end MAPPINGS = [ - Mapping.new(:document_series), Mapping.new(:document_collections), Mapping.new(:organisations), Mapping.new(:policy_areas), diff --git a/lib/search/registries.rb b/lib/search/registries.rb index 897e9d3bc..59fd36b4a 100644 --- a/lib/search/registries.rb +++ b/lib/search/registries.rb @@ -15,7 +15,6 @@ def as_hash # than "topic", we will expand `policy_areas` with data from documents # with format `topic`. policy_areas: registry_for_document_format("topic"), - document_series: registry_for_document_format("document_series"), document_collections: registry_for_document_format("document_collection"), world_locations: registry_for_document_format("world_location"), people: govuk_registry_for_document_format("person"), diff --git a/lib/tasks/report_inconsistent_aggregate_values.rake b/lib/tasks/report_inconsistent_aggregate_values.rake index 2969dfa44..88c0aa775 100644 --- a/lib/tasks/report_inconsistent_aggregate_values.rake +++ b/lib/tasks/report_inconsistent_aggregate_values.rake @@ -9,7 +9,6 @@ task :report_inconsistent_aggregate_values do # Same as in `lib/search/presenters/entity_expander.rb` minus # the content_id mappings which are not valid aggregate fields. aggregates = %w[ - document_series document_collections organisations policy_areas From ded46e86921c6621821c305f7689d4b8142db232 Mon Sep 17 00:00:00 2001 From: Emma Date: Thu, 30 Apr 2026 16:27:49 +0100 Subject: [PATCH 2/5] Point registry for document_collections to govuk index Registries are used to expand fields on elasticsearch documents before they are presented to search API. "document_collection" is a migrated format, so the field "document_collections" should be expanded using content from the govuk index, instead of the government index. See PR where "document_collections" field was reinstated for additional context: https://github.com/alphagov/search-api/pull/3215 --- lib/search/registries.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/search/registries.rb b/lib/search/registries.rb index 59fd36b4a..a2fde965b 100644 --- a/lib/search/registries.rb +++ b/lib/search/registries.rb @@ -15,7 +15,7 @@ def as_hash # than "topic", we will expand `policy_areas` with data from documents # with format `topic`. policy_areas: registry_for_document_format("topic"), - document_collections: registry_for_document_format("document_collection"), + document_collections: govuk_registry_for_document_format("document_collection"), world_locations: registry_for_document_format("world_location"), people: govuk_registry_for_document_format("person"), roles: govuk_registry_for_document_format("ministerial_role"), From b116d61d95bcf029499d89d8b46093e9d3b48692 Mon Sep 17 00:00:00 2001 From: Emma Date: Thu, 30 Apr 2026 16:50:41 +0100 Subject: [PATCH 3/5] Remove registry for policy_areas The "policy_areas" field has been deprecated and is no longer being indexed into elasticsearch [1]. There are no documents in elasticsearch with this field populated in the govuk index, so we no longer need the registry that expands the field. [1] https://github.com/alphagov/whitehall/pull/5666 --- lib/search/presenters/entity_expander.rb | 1 - lib/search/registries.rb | 7 ------- .../report_inconsistent_aggregate_values.rake | 1 - spec/unit/result_set_presenter_spec.rb | 14 +++++++------- 4 files changed, 7 insertions(+), 16 deletions(-) diff --git a/lib/search/presenters/entity_expander.rb b/lib/search/presenters/entity_expander.rb index 80561ef6e..efac78f40 100644 --- a/lib/search/presenters/entity_expander.rb +++ b/lib/search/presenters/entity_expander.rb @@ -33,7 +33,6 @@ def initialize(registry_name, new_field_name: nil) MAPPINGS = [ Mapping.new(:document_collections), Mapping.new(:organisations), - Mapping.new(:policy_areas), Mapping.new(:world_locations), Mapping.new(:people), Mapping.new(:roles), diff --git a/lib/search/registries.rb b/lib/search/registries.rb index a2fde965b..c4d198f87 100644 --- a/lib/search/registries.rb +++ b/lib/search/registries.rb @@ -8,13 +8,6 @@ def as_hash @as_hash ||= { organisations:, organisation_content_ids: organisations, - - # Whitehall has a thing called `topic`, which is being renamed to "policy - # area", because there already are seven things called "topic". Until - # Whitehall publishes the policy areas with format "policy_area" rather - # than "topic", we will expand `policy_areas` with data from documents - # with format `topic`. - policy_areas: registry_for_document_format("topic"), document_collections: govuk_registry_for_document_format("document_collection"), world_locations: registry_for_document_format("world_location"), people: govuk_registry_for_document_format("person"), diff --git a/lib/tasks/report_inconsistent_aggregate_values.rake b/lib/tasks/report_inconsistent_aggregate_values.rake index 88c0aa775..e5288439d 100644 --- a/lib/tasks/report_inconsistent_aggregate_values.rake +++ b/lib/tasks/report_inconsistent_aggregate_values.rake @@ -11,7 +11,6 @@ task :report_inconsistent_aggregate_values do aggregates = %w[ document_collections organisations - policy_areas world_locations people ] diff --git a/spec/unit/result_set_presenter_spec.rb b/spec/unit/result_set_presenter_spec.rb index 9e7899aa4..6321500ba 100644 --- a/spec/unit/result_set_presenter_spec.rb +++ b/spec/unit/result_set_presenter_spec.rb @@ -32,7 +32,7 @@ def sample_docs "_source" => { "title" => "Dairy farming and schemes", "link" => "/dairy-farming-and-schemes", - "policy_areas" => %w[farming], + "document_collections" => %w[farming], }, }] end @@ -157,9 +157,9 @@ def search_presenter(options) context "results with a registry" do before do - policy_area_registry = { + document_collections_registry = { "farming" => { - "link" => "/government/topics/farming", + "link" => "/government/collections/farming", "title" => "Farming", }, } @@ -167,11 +167,11 @@ def search_presenter(options) @output = described_class.new( search_params: Search::QueryParameters.new( start: 0, - return_fields: %w[policy_areas], + return_fields: %w[document_collections], aggregate_name: :aggregates, ), es_response: sample_es_response, - registries: { policy_areas: policy_area_registry }, + registries: { document_collections: document_collections_registry }, ).present end @@ -208,10 +208,10 @@ def search_presenter(options) it "have the expanded topic" do result = @output[:results][2] expect([{ - "link" => "/government/topics/farming", + "link" => "/government/collections/farming", "title" => "Farming", "slug" => "farming", - }]).to eq result["policy_areas"] + }]).to eq result["document_collections"] end end end From d1d7150e36b2532111b23a7b759be41104f94f39 Mon Sep 17 00:00:00 2001 From: Emma Date: Thu, 30 Apr 2026 17:39:43 +0100 Subject: [PATCH 4/5] Point registry for world_locations to govuk index Registries are used (in part) to expand fields on elasticsearch documents before they are presented to search API. This works by mapping the slug stored in the field to documents of the relevant format, and taking additional information from the mapped document. The "world_location" format is no longer being used: there are no documents with this format stored in elasticsearch. However, the field "world_locations" is used in many places (for example as a filter on many finders) and the registry field expansion changes the format of the field [1][2] from the raw elasticsearch document from something that looks like: "world_locations" : ["bulgaria"], to something that looks like: "world_locations": [{"slug": "bulgaria"}], We don't yet understand the consequences of changing the formatting on this field, so want to preserve it. As a quick way to keep this formatting change, but remove references to the registry_index (as we prepare to deprecate the government index), we can use the govuk index to 'expand' the field. Even though it adds no additional information (as before), this will preserve the formatting change. [1] https://github.com/alphagov/search-api/blob/main/lib/search/presenters/entity_expander.rb#L75 [2] https://github.com/alphagov/search-api/blob/main/lib/search/presenters/field_presenter.rb#L33 --- lib/search/registries.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/search/registries.rb b/lib/search/registries.rb index c4d198f87..d9fc0e4be 100644 --- a/lib/search/registries.rb +++ b/lib/search/registries.rb @@ -9,7 +9,7 @@ def as_hash organisations:, organisation_content_ids: organisations, document_collections: govuk_registry_for_document_format("document_collection"), - world_locations: registry_for_document_format("world_location"), + world_locations: govuk_registry_for_document_format("world_location"), people: govuk_registry_for_document_format("person"), roles: govuk_registry_for_document_format("ministerial_role"), } From c7d518807845a60ba1775ab35f7f21556506e78e Mon Sep 17 00:00:00 2001 From: Emma Date: Thu, 30 Apr 2026 18:27:11 +0100 Subject: [PATCH 5/5] Remove registry_index Now all registries pull information from the govuk index, we can remove the registry_index that points to the government index. --- elasticsearch.yml | 2 -- lib/search/registries.rb | 8 -------- lib/search_config.rb | 1 - 3 files changed, 11 deletions(-) diff --git a/elasticsearch.yml b/elasticsearch.yml index e495d6f2f..dd1c4c37e 100644 --- a/elasticsearch.yml +++ b/elasticsearch.yml @@ -3,7 +3,6 @@ production: &default content_index_names: ["government"] govuk_index_name: "govuk" auxiliary_index_names: ["page-traffic", "metasearch"] - registry_index: "government" metasearch_index_name: "metasearch" page_traffic_index_name: "page-traffic" popularity_rank_offset: 10 @@ -21,7 +20,6 @@ test: content_index_names: ["government_test"] govuk_index_name: "govuk_test" auxiliary_index_names: ["page-traffic_test", "metasearch_test"] - registry_index: "government_test" metasearch_index_name: "metasearch_test" page_traffic_index_name: "page-traffic_test" popularity_rank_offset: 10 diff --git a/lib/search/registries.rb b/lib/search/registries.rb index d9fc0e4be..7f8e47cc9 100644 --- a/lib/search/registries.rb +++ b/lib/search/registries.rb @@ -54,14 +54,6 @@ def govuk_index search_server.index_for_search([SearchConfig.govuk_index_name]) end - def registry_for_document_format(format) - BaseRegistry.new(index, field_definitions, format) - end - - def index - search_server.index_for_search([SearchConfig.registry_index]) - end - def field_definitions @field_definitions ||= search_server.schema.field_definitions end diff --git a/lib/search_config.rb b/lib/search_config.rb index 703fb9471..766f66a55 100644 --- a/lib/search_config.rb +++ b/lib/search_config.rb @@ -3,7 +3,6 @@ class << self attr_writer :instance %w[ - registry_index metasearch_index_name popularity_rank_offset auxiliary_index_names