Skip to content

feat(schema): add list-fields, Solr's Luke field listing as FieldFlag records - #288

Merged
epugh merged 6 commits into
apache:mainfrom
adityamparikh:feat/list-fields-241
Nov 24, 2026
Merged

epugh merged 6 commits into
apache:mainfrom
adityamparikh:feat/list-fields-241

Conversation

@adityamparikh

@adityamparikh adityamparikh commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #292 (get-schema records, FieldFlags): its two commits are included here because the field flags reuse its FieldFlags. Review the other four; once #292 merges this is rebased and they are all that remain.

Summary

Adds list-fields: the fields that hold data in a collection, as Solr's Luke handler reports them, returned as a FieldListing record with each field's flags decoded into SolrJ's FieldFlag. One collection-level Luke request.

listFields(collection)
  solrClient.request(LukeRequest numTerms=0 includeIndexFieldFlags=false)
  objectMapper.convertValue(response.get("fields"), Map<String, IndexedField>)   # SimpleOrderedMap is a Map
FieldListing(fields)
  IndexedField(type, flags, dynamicBase, docs: Long, other)   # compact constructor decodes "schema" into flags
                                                              # index section left out: get-collection-stats
                                                              # covers it, and directory names a host path
"platform": {
  "type": "string",
  "flags": ["INDEXED", "STORED", "DOC_VALUES", "OMIT_NORMS", "OMIT_TF", "SORT_MISSING_LAST"],
  "docs": 61
}
  • The flags are FieldFlag names, the enum get-schema uses since feat(schema): return get-schema as CollectionSchema records with FieldFlag flags #292, so Luke's schema letters ("I-SD------OF-----l") and its info.key legend are not needed and are left out.
  • The letters are decoded with FieldFlag.getFlag, not LukeResponse.FieldInfo.parseFlags, which adds getFlag's result without a null check and would throw on a letter a later Solr version adds. On an unknown letter the letters are kept as schema in the catch-all.
  • docs is a Long, so a distributed sum past 2^31 does not depend on how it was parsed (SolrJ's LukeResponse.FieldInfo casts it to Integer).
  • Every other property Luke sends is kept in a @JsonAnySetter @JsonAnyGetter catch-all and written back at the same level.

The same JSON is served as solr://{collection}/fields, with collection-name completion. Where Solr's answer needs reading with care, the tool description says so rather than the server changing it:

  • point and docValues-only fields have no docs count (missing, or 0 on 9.11+/10.1+), which means "not counted"
  • before Solr 9.11/10.1, Luke reads one shard of a multi-shard collection (SOLR-8127)
  • facet only on DOC_VALUES fields, and sort only on ones without MULTI_VALUED

Several tools talk about fields, so each description now names the tool for the job it doesn't do:

 list-fields           fields that hold data; use get-schema before changing the schema
-get-schema            "Get schema for a Solr collection"
+get-schema            definitions and patterns (*_s); does not say which fields hold data
-get-collection-stats  "Get stats/metrics on a Solr collection"
+get-collection-stats  index size and performance; does not describe fields
 search
-  dynamic-suffix guide (_s, _i, _t, ...) + books example document
+  call list-fields first; facet and sort only on docValues fields
-  error hints: "call get-schema"
+  error hints: "call list-fields"

The server instructions and step 1 of search-collection follow the same split, and view-schema points at list-fields for which dynamic fields are in use. McpToolRegistrationTest.fieldToolDescriptionsRouteToEachOther pins the cross-references.

Closes #241. It answers the first two questions of the dev@ Discovery Handler proposal (which fields exist, which are populated) with what Solr has today.

Evidence

  • Before: get-schema on _default returns about 35 KB, and a collection holding genre_s shows only the pattern *_s. Faceting on the schemaless text_general platform returned an empty facet, because nothing said it lacks docValues.
    After: list-fields returns genre_s with "dynamicBase": "*_s", its type, flags and docs, and platform's flags show whether DOC_VALUES is there.
  • ListFieldsIntegrationTest (Testcontainers):
    • one shard: genre_s → dynamicBase *_s, docs 2, flags INDEXED, STORED, DOC_VALUES; id has no dynamicBase; year_i (pint) has no docs, has DOC_VALUES and not MULTI_VALUED; no info or index section
    • two shards (implicit router, a field only on each shard): on 9.11+/10.1+ both fields are listed with docs 1, on older Solr exactly one is, with the expectation taken from the Solr version
  • SchemaServiceTest: listFields_decodesFlagsAndLeavesOutTheInfoAndIndexSections pins the exact JSON; listFields_keepsADistributedDocCountPastIntegerMax (3,000,000,000); listFields_keepsTheLettersWhenOneIsNotAKnownFlag ("I-S-----------Z" gives no flags and keeps the letters).
  • McpClientIntegrationTestBase.listShowsFieldsReturnsIndexedFields, through Spring AI's serialization: no info, id has flags with INDEXED and STORED, no schema letters.
  • ./gradlew build (default solr:9.9.0-slim): 478 tests, 0 failures, 0 skipped. This covers the single-core path.
  • ./gradlew nativeTest -Pnative: 316 successful, 0 failed; ListFieldsIntegrationTest and the MCP list-fields tests (HTTP and STDIO) pass in the native image. The skipped tests are the @DisabledInNativeImage Mockito tests.
  • 9.11 is added to both compatibility matrices, so CI covers the distributed path; 10-slim (10.1) joins once test: start embedded ZooKeeper with -DzkRun=true so Solr 10.1 boots #285 lets it boot.

Merge Danger

Door: two-way

One new read-only tool and resource; reverting removes them.

Blast Radius: descriptions

The search description no longer carries the dynamic-suffix guide, and its error hints name list-fields instead of get-schema. A client that relied on that text to guess field names now has to call list-fields, which is the point, but it changes how existing clients are steered. The compatibility matrices gain a 9.11-slim job.

🤖 Generated with Claude Code

adityamparikh and others added 6 commits November 16, 2026 20:54
…gh (apache#241)

get-schema returns the full schema definition (about 35 KB on _default) and
cannot say which dynamic fields hold data. list-fields sends one
collection-level Luke request (numTerms=0, includeIndexFieldFlags=false) and
returns Luke's fields and info sections as Solr sends them; info.key decodes
the schema flag letters. The index section is left out: get-collection-stats
covers it, and its directory entry names a path on the Solr host. The same
JSON is served as the solr://{collection}/fields resource, with
collection-name completion.

The server adds no logic of its own. The tool description says how to read
Solr's answer: point and docValues-only fields have no docs count (missing,
or 0 on 9.11+/10.1+), and before Solr 9.11/10.1 Luke reads one shard of a
multi-shard collection (SOLR-8127).

The field tools now name each other so a model can tell them apart:
get-schema is definitions and patterns, get-collection-stats is index size
and performance, and search drops its suffix guide in favour of calling
list-fields first. Its undefined-field and facet error hints point to
list-fields. A registration test pins the cross-references.

Closes apache#241

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
- Read Luke's raw NamedList with solrClient.request() instead of process(),
  which also builds SolrJ's typed LukeResponse: that parse casts each docs
  count to Integer and fails on a distributed sum past 2^31.
- Move the docValues advice to the error path it applies to. Solr rejects a
  facet or sort on an unsuitable field with a 400, which gets the generic
  hint; RESPONSE_ERROR is a client-side parse failure. The search
  description and search-collection prompt also say sorting needs a
  single-valued field.
- ListFieldsIntegrationTest: an unknown collection is a SolrException 404,
  and the comment on point-field docs names the right Solr code path.
- Test against Solr 9.11, the first release with distributed Luke: added to
  both compatibility matrices and the tested-version lists. The full suite
  passes on solr:9.11-slim, which runs the two-shard test's distributed
  branch.
- Update the tool and resource counts and lists in THREAT_MODEL.md,
  CHANGELOG.md and the client docs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
- java:S1192: the Luke key constant LUKE_FIELDS_KEY ("fields") made Sonar
  ask the add-fields parameter check to reuse it, though that "fields" is
  an error-message name, not a Luke key. One list of the Luke sections to
  pass through replaces the two key constants.
- java:S5785: assertNotEquals instead of assertTrue(a != b).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
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>
…ag flags

list-fields passed Luke's fields and info sections through as maps. An
agent had to decode each field's schema letters ("I-SD------OF-----l")
with the info.key legend to learn, for example, whether it can facet on
the field.

It now returns a FieldListing record. Each field's letters are decoded
into SolrJ's FieldFlag, the enum get-schema uses, so the info legend is
no longer needed and is left out. docs is a Long, so a distributed sum
past 2^31 no longer depends on how the value was parsed. Every other
property Luke sends is kept in a catch-all and written back at the same
level.

The letters are decoded with FieldFlag.getFlag rather than
LukeResponse.FieldInfo.parseFlags, which adds getFlag's result without a
null check and so would throw on a letter a later Solr version adds. On
an unknown letter the letters are kept as they are.

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>
@sonarqubecloud

Copy link
Copy Markdown

@adityamparikh adityamparikh changed the title feat(schema): add list-fields, Solr's Luke field listing passed through feat(schema): add list-fields, Solr's Luke field listing as FieldFlag records Nov 24, 2026
@epugh
epugh merged commit bdc8f36 into apache:main Nov 24, 2026
2 checks passed
adityamparikh added a commit to adityamparikh/solr-mcp that referenced this pull request Nov 24, 2026
…ctionSchema

get-schema returns the CollectionSchema record since apache#288, so the test
reads field names with fields() and name() instead of SchemaRepresentation's
getFields() map.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
adityamparikh added a commit to adityamparikh/solr-mcp that referenced this pull request Nov 24, 2026
…ration test

apache#288 renamed GET_SCHEMA_HINT_FORMAT to LIST_FIELDS_HINT_FORMAT when the
undefined-field hint started pointing at list-fields.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
adityamparikh added a commit to adityamparikh/solr-mcp that referenced this pull request Nov 24, 2026
…r:read (#66)

list-fields, solr://{collection}/fields and the fields resource's
collection completion arrived with apache#288 on isAuthenticated(). They are
read-only, so they take McpAuthorities.READ and join the expected scope
map and the http.md scope table.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
epugh pushed a commit that referenced this pull request Nov 24, 2026
…ctionSchema (#302)

get-schema returns the CollectionSchema record since #288, so the test
reads field names with fields() and name() instead of SchemaRepresentation's
getFields() map.

Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
adityamparikh added a commit to adityamparikh/solr-mcp that referenced this pull request Nov 24, 2026
…ueryFields

apache#271 gives a collection created without a configSet its own copy of
_default, so rule 1 no longer says collections share a schema by default:
only a named configSet is shared. indexing.md and troubleshooting.md say
the same about guessed fields and add-fields "already exists".

apache#288 added list-fields and solr://{collection}/fields. The tool table
lists it next to get-schema, the description names it, and the search
error rows point to it, as the server's own hints now do. solr-versions.md
states list-fields' version-dependent counts.

apache#291's queryFields local-params error gets a troubleshooting row, and the
Markdown empty-input message is the one the server now returns.

SolrSkillFormatTest is reformatted to google-java-format (apache#266).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
adityamparikh added a commit to adityamparikh/solr-mcp that referenced this pull request Nov 24, 2026
…r:read (#66)

list-fields, solr://{collection}/fields and the fields resource's
collection completion arrived with apache#288 on isAuthenticated(). They are
read-only, so they take McpAuthorities.READ and join the expected scope
map and the http.md scope table.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
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.

schema: add list-fields, the fields a collection actually holds

2 participants