Add endpoint to get aggregate count for metadata fields #4507
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
How did we make this PR?
This was all generated by Copilot Agent mode with Claude Sonnet 4 during a focused group session with the Newsroom AI. Initial prompt was:
Does it work?
Yes! Copilot was actually able to re-use some existing (but possibly unused?) functionality, and created a test which exercises the new
size
param which it added. The test does not actually exercise the new endpoint itself, just the function used by the endpoint.You can also verify yourself with
Is it perfect!
No! Flaws we know about:
keyword
mapping type. This is an elasticsearch limitationCopilot documentation
On our request, Copilot produced the following documentation.
It has a few mistakes, namely:
localhost
curl requests won't work because of auth (you need*.media.local.dev-gutools.co.uk
)country
will not work, because it doesn't have akeyword
field typeOverview
This new endpoint provides the top N values with counts for metadata fields, enabling Kibana-style filtering functionality. It's the first step towards replacing the chips-based search with explicit UI filters.
Endpoint
Parameters
field
(required): The metadata field to aggregate on (e.g., "country", "city", "credit", etc.)size
(optional, default: 10): Maximum number of top values to returnq
(optional): Additional query to filter the data before aggregationExample Usage
Get top 5 countries from all images:
curl "http://localhost:9001/images/aggregations/metadata/keyword?size=5"
Get top countries from images with "london" in any field:
curl "http://localhost:9001/images/aggregations/metadata/keyword?q=london&size=5"
Example Response
Supported Fields
All metadata fields are supported, including:
country
,city
,state
,subLocation
credit
,source
,supplier
byline
,photographer
keywords
,subjects
title
,description
imageType
Technical Implementation
metadataSearch
functionality inElasticSearch
classq
parameterNext Steps
This endpoint will be used to build explicit filter UI components that show:
This will replace the current chips-based system where users need to know specific syntax like
country:UK
.