Skip to content

Add /indexes/{indexUID}/fields route to get all field names #5718

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

qdequele
Copy link
Member

@qdequele qdequele commented Jun 27, 2025

Summary

This PR adds a new dedicated route /indexes/{indexUID}/fields that returns a complete list of all field names in an index, including nested fields. This provides a lightweight alternative to the stats route for clients that only need field information without the overhead of field distribution calculations.

Changes Made

1. Route Details

  • Endpoint: GET /indexes/{indexUid}/fields
  • Response: Array of strings containing all field names (e.g., ["id", "title", "user.name", "user.email"])
  • Authentication: Requires indexes.get permission
  • Error Handling: Returns 404 for non-existent indexes with proper error format

2. Implementation Details

  • Uses FieldsIdsMap::names() to get all field names including nested fields
  • Returns field names in dot notation format (e.g., user.profile.age)
  • No performance impact on indexing as it only reads existing field metadata
  • Includes both top-level and deeply nested fields

3. Testing

  • Added fields() method to test utilities in crates/meilisearch/tests/common/index.rs
  • Added comprehensive test suite in crates/meilisearch/tests/index/stats.rs:
    • Basic functionality test with simple nested fields
    • Complex nested fields test with up to 6 levels of nesting
    • Error handling test for non-existent indexes
    • Verification of field name format and uniqueness

Example Usage

# Get all fields from an index
GET /indexes/movies/fields

# Response
[
  "id",
  "title", 
  "user.name",
  "user.email",
  "metadata.category",
  "metadata.author.name"
]

Breaking Changes

None - this is a new route that doesn't affect existing functionality.
no db change

qdequele added 2 commits June 27, 2025 21:28
This commit introduces a new API endpoint `/indexes/{indexUid}/fields` that allows users to fetch all field names in an index, including nested fields. It also includes corresponding tests to validate the functionality, ensuring that the endpoint returns the correct fields for both empty and populated indexes, as well as handling errors for non-existent indexes.
@qdequele qdequele closed this Jun 28, 2025
@qdequele qdequele reopened this Jun 28, 2025
@Kerollmops Kerollmops added this to the v1.16.0 milestone Jun 29, 2025
@ManyTheFish
Copy link
Member

Hey @qdequele,

After discussing with the team, we could accept a minimal implementation that doesn't contain the field Metadata.
However, for future proofing, we'd like the below changes before merging the PR:

  1. the simple array of string must be transformed into an array of object containing a name field like [{"name": "title"}, ..], this will allow us to add metadata related to the field in the future.
  2. instead of a GET query, we'd prefer having a POST query allowing us to extend the request body easily.
  3. the response should be paginated, we can have up to 16535 fields in a single index, fortunatelly it's a rare case, but it remains possible ☺️

The keys API use an autopagination helper, see below:

let keys = auth_controller.list_keys()?;
let page_view = paginate
.auto_paginate_sized(keys.into_iter().map(|k| KeyView::from_key(k, &auth_controller)));
Ok(page_view)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants