Skip to content

Remove runtime mappings from CDR data grid queries#254742

Merged
maxcold merged 9 commits intomainfrom
fix/198651-remove-runtime-mappings
Feb 27, 2026
Merged

Remove runtime mappings from CDR data grid queries#254742
maxcold merged 9 commits intomainfrom
fix/198651-remove-runtime-mappings

Conversation

@maxcold
Copy link
Copy Markdown
Contributor

@maxcold maxcold commented Feb 24, 2026

Summary

Removes client-side runtime mappings from CDR (Cloud Detection & Response) misconfigurations and vulnerabilities data grid queries. These runtime mappings were a workaround (#198635) for missing keyword mappings in 3rd-party integration indexes (e.g. Wiz), which caused sorting and grouping to fail.

Why they're no longer needed: The ecs@mappings component template — which includes a catch-all all_strings_to_keywords dynamic mapping rule — is now applied to all Fleet transform destination index templates (#223878). This means all string fields in CDR latest indexes are automatically mapped as keyword, making the runtime mappings redundant.

What changed:

  • Removed 4 runtime mapping constants from constants.ts
  • Removed getRuntimeMappingsFromSort() from data table query builders (misconfigs + vulns)
  • Removed getRuntimeMappingsByGroupField() from grouping query builders (misconfigs + vulns)
  • Added unmapped_type: 'keyword' to sort fields to handle indexes where a field may not be mapped
  • Fixed painless sort scripts to handle missing fields with doc.containsKey() checks (previously would throw null pointer errors for 3P documents missing native CSP fields)

Closes #198651

Checklist

  • Any text added follows EUI's writing guidelines, uses sentence case text and includes i18n support
  • Documentation was added for features that require explanation or tutorials
  • Unit or functional tests were updated or added to match the most common scenarios
  • If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the docker list
  • This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The release_note:breaking label should be applied in these situations.
  • Flaky Test Runner was used on any tests changed
  • The PR description includes the appropriate Release Notes section, and the correct release_note:* label is applied per the guidelines
  • Review the backport guidelines and apply applicable backport:* labels.

Identify risks

  • Low risk: Sorting by fields missing in some indexes (e.g. rule.benchmark.rule_number for Wiz) now relies on ES unmapped_type instead of runtime mappings. Verified locally that documents are included correctly with missing-field docs appearing at the end of sort results.

Runtime mappings were a workaround for missing keyword mappings in 3P
integration indexes. Now that ecs@mappings component template is applied
to all Fleet transform destination indexes, all string fields are
automatically mapped as keyword, making runtime mappings redundant.

Replace them with unmapped_type: 'keyword' on sort fields and null-safe
painless scripts to handle indexes where fields may not exist.

Closes #198651
@maxcold maxcold requested a review from a team as a code owner February 24, 2026 14:44
@maxcold maxcold added release_note:skip Skip the PR/issue when compiling release notes backport:skip This PR does not require backporting Team:Cloud Security Cloud Security team related labels Feb 24, 2026
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/contextual-security-apps (Team:Cloud Security)

@maxcold maxcold requested a review from alexreal1314 February 24, 2026 14:49
// and an empty string for descending so missing values also sort last.
// Note: Painless double-quoted strings only support \\ and \" escapes,
// so we embed the actual U+FFFF character rather than a \uffff escape sequence.
const missingFallback = direction === 'asc' ? '\uffff' : '';
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this approach with data from generator, seems to be working fine, though look a bit weird

Extract sort logic to common/utils/findings_sort.ts so both the
frontend and integration tests can share the same Painless sort
scripts. Add FTR integration test that validates scripts compile
and execute against real ES, including missing-values-last behavior.
@alexreal1314
Copy link
Copy Markdown
Contributor

tested locally, LGTM, there some issue with the types in the CI.

The `direction` parameter was typed as `string`, causing
`order: direction` to be incompatible with ES client's `SortOrder`
type when the return value is passed to `es.search()`.
EsIndexDataProvider.destroyIndex() now resolves aliases to their
concrete backing indices before calling indices.delete, since ES 9.x
rejects deletion by alias name.
… creation

Use waitForPluginInitialized + deleteAll/addBulk pattern matching
other tests in the same directory, leveraging the integration's
index mappings via the alias rather than creating a custom index.
The test validates Painless sort scripts against ES, not an API route.
@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
cloudSecurityPosture 611 612 +1

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
cloudSecurityPosture 607.7KB 606.7KB -1014.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
cloudSecurityPosture 17.6KB 17.6KB +1.0B
Unknown metric groups

ESLint disabled line counts

id before after diff
@kbn/test-suites-xpack-security 68 70 +2

Total ESLint disabled count

id before after diff
@kbn/test-suites-xpack-security 70 72 +2

History

@maxcold maxcold merged commit 49c8d3b into main Feb 27, 2026
16 checks passed
@maxcold maxcold deleted the fix/198651-remove-runtime-mappings branch February 27, 2026 23:10
qn895 pushed a commit to qn895/kibana that referenced this pull request Mar 11, 2026
## Summary

Removes client-side runtime mappings from CDR (Cloud Detection &
Response) misconfigurations and vulnerabilities data grid queries. These
runtime mappings were a workaround
([elastic#198635](elastic#198635)) for missing
`keyword` mappings in 3rd-party integration indexes (e.g. Wiz), which
caused sorting and grouping to fail.

**Why they're no longer needed:** The `ecs@mappings` component template
— which includes a catch-all `all_strings_to_keywords` dynamic mapping
rule — is now applied to all Fleet transform destination index templates
([elastic#223878](elastic#223878)). This means
all string fields in CDR latest indexes are automatically mapped as
`keyword`, making the runtime mappings redundant.

**What changed:**
- Removed 4 runtime mapping constants from `constants.ts`
- Removed `getRuntimeMappingsFromSort()` from data table query builders
(misconfigs + vulns)
- Removed `getRuntimeMappingsByGroupField()` from grouping query
builders (misconfigs + vulns)
- Added `unmapped_type: 'keyword'` to sort fields to handle indexes
where a field may not be mapped
- Fixed painless sort scripts to handle missing fields with
`doc.containsKey()` checks (previously would throw null pointer errors
for 3P documents missing native CSP fields)

Closes elastic#198651

### Checklist

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)
- [x]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [x] This was checked for breaking HTTP API changes, and any breaking
changes have been approved by the breaking-change committee. The
`release_note:breaking` label should be applied in these situations.
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [x] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
- [x] Review the [backport
guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)
and apply applicable `backport:*` labels.

### Identify risks

- **Low risk**: Sorting by fields missing in some indexes (e.g.
`rule.benchmark.rule_number` for Wiz) now relies on ES `unmapped_type`
instead of runtime mappings. Verified locally that documents are
included correctly with missing-field docs appearing at the end of sort
results.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:Cloud Security Cloud Security team related v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Get rid of runtime mappings for data grid queries

4 participants