Repository navigation
fix(api): refuse a fields format on a type that cannot format, like ES - #2986
Open
amartya1523 wants to merge 4 commits into
Open
amartya1523 wants to merge 4 commits into
amartya1523 wants to merge 4 commits into
Conversation
ES builds a value fetcher for every field a `fields` entry matches, with the entry's format. A type with one rendering (keyword, text, numbers, boolean, ip, flattened, ...) throws, and FieldFetcher wraps it with the entry: "error fetching [f]: Field [f] of type [t] doesn't support formats.", plus "which matched [pattern]" for a wildcard. The shard fails, so the search is a 400. XERJ ignored the format and returned the value unformatted. The check runs after target resolution against each index's mapping, covering multi-fields and keys below a flattened field. Runtime fields are left alone, and a search where some index can format the field still answers, since ES would return a partial result there. Retires the three search/330_fetch_fields.yml error cases.
Exact names, a wildcard, a long, a multi-field and a flattened key are a 400 with ES's reason; dates, geo_point, unmapped names, empty wildcards, runtime fields and a mixed-index search still fetch.
The fields format refusal also makes search/330_fetch_fields.yml's "Test date formatting" (a format on a keyword field, catch: bad_request) pass; CI's runner flagged the catch-lenient line as stale.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AI-assisted change, run and reviewed by @amartya1523.
What this changes, and why
A
fieldsentry can carry aformat({"field": "date", "format": "yyyy/MM/dd"}). In ES,FieldFetcher#createbuilds a value fetcher for every mapped field the entry matches, passing the format. A type with only one rendering refuses it (MappedFieldType#checkNoFormat,SourceValueFetcher.identity).FieldFetcherwraps that with the entry, so the shard fails and the search is a 400 (search_phase_execution_exception, root causeillegal_argument_exception):XERJ ignored the format and returned the value unformatted (
apply_field_formathands back anything that doesn't parse as a date), with a 200. A caller asking for"format": "yyyy"on the wrong field couldn't tell. Threecatch-lenient.txtlines are these cases (search/330_fetch_fields.yml):error includes field nameerror includes glob patternerror for flattened includes whole pathFix (es_compat.rs):
fields_format_failureruns insearch_implafter target resolution (beside the closed-index andallow_no_indiceshandling), so it reads each participating index's mapping. For everyfieldsentry that has a stringformat:name.raw), orflattenedfor a key below a flattened field (flat.some.key), which ES serves through the flattened keyed sub-type.glob_match_simplethe search path uses. A match that can format (saydateunderd*) is passed over, and the first one that can't is reported withwhich matched [pattern].FORMATLESS_FIELD_TYPESfails: keyword, constant_keyword, wildcard, text, match_only_text, boolean, ip, version, the numeric types, token_count and flattened. Dates, geo and range types take a format, and any type not listed is left alone rather than guessed at.mapped_leaf_fieldsbuilds the full-path leaf list: multi-fields included,object/nestednodes excluded, no bare leaf aliases. The existingcollect_leaf_typesadds short names for dotted leaves, which would make a wildcard match fields it shouldn't.search_shard_validation_errorenvelope.Deliberately not refused:
runtime_mappingsor the index'sruntimesection). The runtime type decides there, and this doesn't model it.Evidence
New test module
fields_format_tests(es_compat.rs), run against main first:dkeyword,d*(which also matches thedatefield, passed over), along, a multi-fieldname.rawand a flattened keyflat.bar. Each asserts the 400, the outer type, the root-cause type and ES's exact reason.datewithyyyy/MM/ddstill renders1990/12/29geo_pointwithwktstill answers/test,otherwhereothermaps the field as a date still answersChecks
cargo fmt -p xerj-api -- --checkcargo test --profile quick -p xerj-api --lib: 432 passed, 0 failedfields+formatcases in the suite (date in330_fetch_fields.ymland240_date_nanos.yml, geo_pointgeojson/wkt) are types that take a format.docvalue_fields(where numbers do take a#.0format) isn't touched.Not run locally:
--releasebuilds,clippyand the integration binaries. Disk on this machine is at 99%; CI runs all of these.Provenance
quickprofile, based on main83c9f0d12._msearchdoesn't go throughsearch_impl, so it's not covered.