Repository navigation
Conversation
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.
|
is DELETE /api/collections/collName/schema/copyfields/srcField/dstFields using |
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:
|
epugh
left a comment
There was a problem hiding this comment.
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?
|
^^ is a patch file that converts to using strong typeing and updates the schema.js..... |
|
Feel free to commit to this PR branch |
# Conflicts: # solr/solr-ref-guide/modules/indexing-guide/pages/schema-api.adoc
|
Automated PR readiness judgements (LLM-generated; may be wrong; not updated on later pushes).
|
|
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 ... |
|
Okay, pending a clean CI, I think I am done on this! @janhoy would love your input on the |
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.GETlists the source's rules, including dynamic rules. A source without rules returns an empty list.PUTreplaces the complete set. The body is an array of objects, each with a requireddestand an optionalmaxChars, so destinations can have different limits. An empty array clears the source.POSTadds destinations while preserving existing rules and their limits. Existing destinations are skipped, making retries safe.DELETEremoves every rule for the source, or only destinations named in a trailing comma-separated path segment. Missing rules return 404.For example, a
PUTbody 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
desttodestinationrename is deferred to follow-up PR #5380.Validation: 60 targeted API, serialization, and browser tests passed, along with
./gradlew tidyandcheck -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.