Repository navigation
fix(api): refuse a regex include/exclude on a non-string terms field - #3008
Open
amartya1523 wants to merge 2 commits into
Open
amartya1523 wants to merge 2 commits into
amartya1523 wants to merge 2 commits into
Conversation
terms, rare_terms and significant_terms take include/exclude as an array of values, a partition object, or a string, which is a regular expression. ES applies a regular expression to the terms as strings, so on an ip, numeric, date or boolean field it answers 400 with "Aggregation [name] cannot support regular expression style include/exclude settings as they can only be applied to string fields. Use an array of values for include/exclude clauses". XERJ ran the pattern anyway: terms matched it against the rendered values and rare_terms / significant_terms ignored it. The check sits beside the non-numeric metric check in search_impl and follows its rule: the field is refused only when it has such a type in every target index. Retires the three "IP test" catch-lenient entries (terms, rare_terms, sig_terms).
terms, rare_terms and significant_terms on ip, a regex on an integer and a date, and a sub-aggregation are a 400 with ES's reason; arrays, partitions, string fields, multi-fields, unmapped fields, mixed targets and significant_text still answer.
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
terms,rare_termsandsignificant_termsacceptinclude/excludein three forms:{partition, num_partitions}object,ES only applies a regular expression to terms that are strings. On a field whose values aren't (
IncludeExclude#isRegexBasedwith a non-RAWvalues-source format: ip, numbers, dates, booleans), it refuses the request. That's a 400 since 8.12:XERJ answered 200 in all three aggregations:
termsmatched the pattern against the rendered values, so"exclude": "127.*"on an ip field happened to drop127.0.0.1.rare_termsandsignificant_termsonly read arrays and ignored the string, so the filter silently did nothing.Either way the caller got buckets that didn't mean what the request said. Three
catch-lenient.txtlines are this case, the last step of each "IP test":aggregations/terms.yml · IP testaggregations/rare_terms.yml · IP testaggregations/sig_terms.yml · IP testFix (es_compat.rs): new
find_regex_include_exclude_on_non_string_field, chained afterfind_unsupported_metric_agg_fieldinsearch_impl, at the same point (after the field-alias rewrite, before execution) and with the same rules:terms,rare_termsandsignificant_terms, at any depth. The error names the aggregation that carries the pattern, as ES does.significant_textis left alone because it reads text, and its YAML cases use string patterns on text fields.includeorexcludeis a JSON string. Arrays and partition objects are allowed on every type, as in ES.ip;long,integer,short,byte,double,float,half_float,scaled_float,unsigned_long;date,date_nanos;boolean. Multi-fields resolve throughfields(name.rawis a keyword and stays allowed).search_shard_validation_error: 400search_phase_execution_exceptionwith anillegal_argument_exceptionroot cause.Evidence
New test module
regex_include_exclude_tests(es_compat.rs), run against main first:terms,rare_termsandsignificant_termswith"exclude": "127.*"on an ip"include": "1.*"on an integer"exclude": "2020.*"on a dateAggregation [inner] ...terms,rare_terms)/t,uwhereumaps the field as a longsignificant_textwith a string includeChecks
cargo fmt -p xerj-api -- --checkcargo test --profile quick -p xerj-api --lib: 432 passed, 0 failedcargo clippy --profile quick -p xerj-api --lib --tests: no warnings in the changed code (the local toolchain is newer than CI's 1.97.1 and flags unrelated existing code elsewhere)significant_text/significant_textson text fields, which this doesn't touch. The partition cases interms.yml(keyword and integer) are objects, which stay allowed.Not run locally:
--releasebuilds and the integration binaries. CI runs these.Provenance
quickprofile, based on main34bf35b05.rare_termsandsig_termsYAML regexes;terms.ymlonly assertsbad_request.versionfields aren't in the refused list (I'm not sure of their values-source format in ES), so they keep today's answer._msearchand the template paths don't go throughsearch_impl, so they aren't covered.