Skip to content

feat(schema): return get-schema as CollectionSchema records with FieldFlag flags - #292

Closed
adityamparikh wants to merge 2 commits into
apache:mainfrom
adityamparikh:feat/schema-records
Closed

adityamparikh wants to merge 2 commits into
apache:mainfrom
adityamparikh:feat/schema-records

Conversation

@adityamparikh

@adityamparikh adityamparikh commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

get-schema and solr://{collection}/schema now return a CollectionSchema record instead of SolrJ's SchemaRepresentation.

 getSchema(collection)
-  schemaRequest.process(solrClient, collection)   # SolrJ parses into SchemaRepresentation
-    .getSchemaRepresentation()                    #   FieldTypeDefinition: {attributes:{name,class,...},
-                                                  #   analyzer:null, multiTermAnalyzer:null, similarity:null}
+  solrClient.request(new SchemaRequest(), collection)       # Schema API JSON, objects as SimpleOrderedMap (a Map)
+  objectMapper.convertValue(response.get("schema"), CollectionSchema.class)

The records type what clients read and keep everything else:

CollectionSchema   name, version, uniqueKey, fieldTypes, fields, dynamicFields, copyFields, other
  Field            name, type, flags, required, other
  FieldType        name, className ("class"), flags, analyzer, indexAnalyzer, queryAnalyzer, multiTermAnalyzer, other
  Analyzer         charFilters, tokenizer, filters, other
  CopyField        source, dest, maxChars, other

other is a catch-all marked @JsonAnySetter @JsonAnyGetter. Jackson collects each property the record does not declare into it (positionIncrementGap, vectorDimension, useDocValuesAsStored, similarity, …) and writes it back out at the same level, so a property a later Solr version adds is passed on instead of dropped.

flags is a set of SolrJ's FieldFlag, the enum Luke's flag letters decode to, so get-schema and list-fields describe flags the same way. The compact constructor moves the Schema API's boolean flag properties out of the catch-all:

 {"name": "platform", "type": "string",
-  "docValues": true, "multiValued": false, "indexed": true, "stored": true}
+  "flags": ["INDEXED", "STORED", "DOC_VALUES"]}

Only properties set to true are reported; a property set to false, or inherited from the field type, is not. required has no FieldFlag and stays a typed property. Flags are written as constant names: Jackson 3 writes enums with toString(), which for FieldFlag is Luke's legend text ("D - DocValues"), so FieldFlags.NameSerializer writes name().

The new records and FieldFlags.NameSerializer are registered in SolrNativeHints.MCP_TOOL_RECORDS, and FieldFlag with the SolrJ types; the SchemaRepresentation hint is removed because nothing serializes it any more.

Evidence

  • Before: get-schema on a _default collection returns 32,169 chars, each field type wrapped as {"analyzer":null, "attributes":{"name":"strings","class":"solr.StrField","sortMissingLast":true,"multiValued":true}, "indexAnalyzer":null, "multiTermAnalyzer":null, …}.
    After: 23,297 chars (Solr's own schema section is 23,261): {"name":"strings","class":"solr.StrField","flags":["MULTI_VALUED","SORT_MISSING_LAST"]}.
  • SchemaServiceIntegrationTest.getSchema_isTheSchemaApiResponseWithFlagPropertiesAsFlags: the serialized record equals Solr's Schema API response with each field's, dynamic field's and field type's boolean flag properties replaced by the flags that were true, compared as parsed JSON. getSchema_reportsFieldFlags pins examples (_root_ is INDEXED but not STORED).
  • SchemaServiceTest.getSchema_keepsPropertiesTheRecordsDoNotDeclare: an unknown field property and an unknown top-level section reach the JSON at the level Solr sent them, with no other key; indexed: true, stored: false becomes "flags":["INDEXED"].
  • McpClientIntegrationTestBase.getSchema (through Spring AI's serialization): class sits at the top level of a field type, there is no attributes wrapper and no other key, the arrays are present, and id carries "flags" with INDEXED and STORED instead of booleans.
  • ./gradlew build: 461 tests, 0 failures, 0 skipped.
  • ./gradlew nativeTest -Pnative: 304 successful, 0 failed; the schema integration tests and both MCP getSchema tests (HTTP and STDIO) pass in the native image. The 154 skipped are the @DisabledInNativeImage Mockito tests.

Merge Danger

Door: two-way

Reverting restores the SolrJ type.

Blast Radius: schema-consumers

The JSON shape of get-schema and solr://{collection}/schema changes: field-type properties move out of attributes to the top level, as the Schema API sends them, the null analyzer slots disappear, and boolean flag properties become a flags list. A client that parsed the SolrJ shape, or read indexed/docValues booleans, has to read flags instead; an explicit false is no longer visible. Java callers of SchemaService.getSchema get CollectionSchema instead of SchemaRepresentation.

🤖 Generated with Claude Code

adityamparikh and others added 2 commits November 16, 2026 18:24
get-schema returned SolrJ's SchemaRepresentation, whose FieldTypeDefinition
nests each type's properties under "attributes" and serializes every unset
analyzer slot as null: 32 KB on _default against the Schema API's own 23 KB.

It now returns a CollectionSchema record with typed components for the
properties clients read (fields, field types, analyzers, copy fields).
Every other property Solr sends is kept in a catch-all map, collected by
@JsonAnySetter when the response is converted and written back at the same
level by @JsonAnyGetter, so the JSON a client receives is the Schema API's,
key for key, and a property a later Solr version adds is passed on rather
than dropped.

The response is read with solrClient.request() and converted by Jackson:
the Schema API's JSON objects arrive as SimpleOrderedMap, a java.util.Map,
so no mapping code is needed.

Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
The Schema API's boolean properties (indexed, stored, docValues,
multiValued, omitNorms, sortMissingLast, ...) are now reported on every
field, dynamic field and field type as "flags", a set of SolrJ's
FieldFlag, the enum Luke's flag letters decode to. list-fields uses the
same enum, so both tools describe a field's flags the same way.

Only properties set to true appear: a flag property set to false, or
inherited from the field type, is not reported. required, which
FieldFlag has no counterpart for, stays a typed property; other
properties without one (useDocValuesAsStored, large, default) stay in
the catch-all unchanged.

Flags are written as their constant names (DOC_VALUES). Jackson 3 writes
enums with toString() by default, which for FieldFlag is Luke's legend
text ("D - DocValues").

Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
@adityamparikh adityamparikh changed the title feat(schema): return get-schema as CollectionSchema records feat(schema): return get-schema as CollectionSchema records with FieldFlag flags Nov 17, 2026
@sonarqubecloud

Copy link
Copy Markdown

@adityamparikh

Copy link
Copy Markdown
Contributor Author

Superseded by #288, which merged as bdc8f36 and carried its own versions of both commits here (get-schema as CollectionSchema records, and field/field-type flags as SolrJ FieldFlag). Nothing in this branch is missing from main.

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.

1 participant