Skip to content

SOLR-18479: Add v2 copy-field endpoints to the Schema API - #4943

Open
janhoy wants to merge 10 commits into
apache:mainfrom
janhoy:SOLR-18479-v2-copyfield-api
Open

janhoy wants to merge 10 commits into
apache:mainfrom
janhoy:SOLR-18479-v2-copyfield-api

Conversation

@janhoy

@janhoy janhoy commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

https://issues.apache.org/jira/browse/SOLR-18479

Copy-field rules gain dedicated v2 endpoints under /api/collections/{collection}/schema/copyfields/{sourceField} (or /api/cores/{core}/schema/copyfields/{sourceField}). The source identifies the set of copy rules.

  • GET lists the source's rules, including dynamic rules. A source without rules returns an empty list.
  • PUT replaces the complete set. The body is an array of objects, each with a required dest and an optional maxChars, so destinations can have different limits. An empty array clears the source.
  • POST adds destinations while preserving existing rules and their limits. Existing destinations are skipped, making retries safe.
  • DELETE removes every rule for the source, or only destinations named in a trailing comma-separated path segment. Missing rules return 404.

For example, a PUT body can be:

[
  {"dest": "title_facet", "maxChars": 100},
  {"dest": "title_sort", "maxChars": 20}
]

The rules are applied together by SchemaManager, using the existing update lock and retry boundary. Invalid replacements leave the previous rules intact. The Admin UI uses the generated client to append and delete rules, with an optional character-limit input.

Existing v1 behavior and existing v2 read/bulk naming remain unchanged. The v2 dest to destination rename is deferred to follow-up PR #5380.

Validation: 60 targeted API, serialization, and browser tests passed, along with ./gradlew tidy and check -x test. The latter used a temporary source-scan exclusion for unrelated local .claude/worktrees/; repository build files are unchanged. The full test suite was not run.

Developed with Claude AI and OpenAI Codex assistance.

Fields, dynamic fields and field types each have PUT/DELETE routes in the v2
Schema API; copy-fields were the one resource left reachable only through
/schema/bulk. The routes had been sketched out and commented out, with a TODO
noting that copy-field rules have no name to address them by.

Address them by source field instead: PUT /schema/copyfields/{sourceField}
takes a destinations list in the body, and DELETE removes every rule with that
source unless 'destination' query parameters narrow the selection. Deleting a
source that has no rules answers 404 rather than silently succeeding.

The source-addressed shape means one request covers a 1:many fan-out, at the
cost of the path naming a set of rules rather than a single one. Enumerating
the destinations for an unqualified DELETE goes through
IndexSchema.getCopyFieldProperties so that glob rules are covered as well as
explicit ones.

The ref guide's v2 copy-field examples are updated to the new endpoints; they
previously showed a v1 keyed-object body POSTed to /schema, which that path
answers with a 405 since it only carries GET.
The underlying 'add-copy-field' operation is purely additive: registerCopyField
appends a rule without checking whether an identical one is already present, so
PUTting the same destinations twice left the source copied twice over at index
time. That breaks PUT's idempotency contract, and it also meant the body could
only ever state the rules being added rather than the rules the caller wanted.

Clear the source's existing rules as part of the same SchemaManager operation
list, so the destinations in the body become the complete set for that source.
Applying both operations as a unit keeps the change transactional: a rejected
replacement leaves the previous rules in place.

Renamed the endpoint method to upsertCopyFields, since 'add' no longer describes
what it does.  Adding a destination while keeping the others now means either
listing them all, or using add-copy-field through the bulk endpoint, which still
only appends; the ref guide spells out both, along with the duplicate hazard of
the additive operation.
Rounds out /schema/copyfields/{sourceField} so the whole resource is addressed
through the path rather than partly through query parameters:

  GET    /copyfields/{source}                 the source's rules
  PUT    /copyfields/{source}                 set the complete destination list
  POST   /copyfields/{source}                 append destinations
  DELETE /copyfields/{source}                 remove all of the source's rules
  DELETE /copyfields/{source}/{destinations}  remove the named ones

The 'destination' query parameter is gone; a trailing path segment names the
destinations instead, several at a time as a comma-separated list. Splitting
goes through StrUtils.splitSmart so a separator inside quotes or behind a
backslash does not split; it does not trim, so surrounding whitespace (which can
only arrive percent-encoded) is dropped separately.

POST appends without disturbing the rules already in place, which PUT cannot do
without a read-modify-write, and which therefore avoids losing one of two
concurrent appends. Destinations the source already copies to are skipped rather
than appended a second time, so a retried POST is harmless -- worth having for a
caller that timed out without learning whether its first attempt landed.

GET by source overlaps the existing source.fl query parameter on /copyfields,
but reads the resource at the path the write verbs use, so the ref guide leads
with it and presents source.fl as the alternative for filtering by destination
or by several sources at once.
The replace and append operations worked out which rules to remove or skip in
the resource method, before handing SchemaManager a fixed list of operations.
That read happens outside the schema update lock, while doOperations takes the
lock, refreshes the schema and replays the operations on every retry. The list
could therefore be stale precisely when it mattered: a concurrently added
destination survived a replace, and a retry triggered by another node's change
could fail with "Copy field directive not found" for a rule that had since been
removed.

Move the diffing into two internal-only operations, upsert-copy-field and
append-copy-field, alongside the existing internal upsert-field. They inspect
managedIndexSchema, which doOperations refreshes under the lock, so each attempt
diffs against the rules actually in effect. Append builds a fresh operation
rather than narrowing the caller's, so a retry does not inherit the previous
attempt's filtering.

Deleting every rule for a source now goes through the same path, by replacing
its rules with none; the remaining out-of-lock read is only to report 404 for a
source that has no rules at all.

Also from review:
 - A path segment naming no destinations, e.g. /copyfields/src/,,, answered 404
   claiming the source had no rules, when the request was simply malformed and
   the source may well have rules. It is now a 400.
 - A request body whose 'source' contradicts the path was silently overwritten;
   it is now rejected.
 - Documented that a PUT with an empty destinations list clears the source, and
   that a GET for a source with no rules returns an empty list rather than 404.
   The test setup uses the former to reset state, which no longer needs to
   swallow a 404.
@github-actions github-actions Bot added documentation Improvements or additions to documentation tests cat:api cat:schema labels Sep 24, 2026
@epugh

epugh commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

is DELETE /api/collections/collName/schema/copyfields/srcField/dstFields using dstFields a bit not aligned with POST /api/collections/collName/schema/copyfields/srcField {"destinations":[]...} ? Should they both be dstFields ? not destiations?

@janhoy

janhoy commented Sep 25, 2026

Copy link
Copy Markdown
Contributor Author

is DELETE /api/collections/collName/schema/copyfields/srcField/dstFields using dstFields a bit not aligned with POST /api/collections/collName/schema/copyfields/srcField {"destinations":[]...} ? Should they both be dstFields ? not destiations?

The delete api operates on plain field-names only, the POST api needs a body.

Example use of DELETE, which would delete to copyField rules:

DELETE /api/collections/collName/schema/copyfields/title/title_facet,title_sort

@epugh epugh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pushing forward on this...... I put some comments in... I don't know if you want me to muck around in this branch?

@epugh

epugh commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

eric_solr_18479_changes.patch

^^ is a patch file that converts to using strong typeing and updates the schema.js.....

@janhoy

janhoy commented Sep 26, 2026

Copy link
Copy Markdown
Contributor Author

Feel free to commit to this PR branch

@epugh epugh self-assigned this Sep 27, 2026
@epugh
epugh marked this pull request as ready for review November 22, 2026 13:32
@github-actions

Copy link
Copy Markdown

Automated PR readiness judgements (LLM-generated; may be wrong; not updated on later pushes).

@epugh

epugh commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

I update the solr Admin UI and played around witht he new api, looks good. We are down to a "replace-field" call that is being used ...

@epugh epugh added this to the 10.x milestone Nov 22, 2026
@epugh

epugh commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Okay, pending a clean CI, I think I am done on this! @janhoy would love your input on the maxChars appraoch I took. Once this merges, then the follow up dest to destination rename will happen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

admin-ui cat:api cat:schema documentation Improvements or additions to documentation tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants