Skip to content

Map calculated value fields according to their configured element type - #488

Open
andreaswagner-rnab wants to merge 2 commits into
pimcore:2026.2from
andreaswagner-rnab:fix/calculated-value-element-type-mapping
Open

Map calculated value fields according to their configured element type#488
andreaswagner-rnab wants to merge 2 commits into
pimcore:2026.2from
andreaswagner-rnab:fix/calculated-value-element-type-mapping

Conversation

@andreaswagner-rnab

@andreaswagner-rnab andreaswagner-rnab commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Fixes pimcore/platform-version#293

Problem

Calculated value fields are always indexed with the generic text/keyword mapping, regardless of their configured element type (calculatedValue is registered on TextKeywordAdapter in field-definition-adapters.yml).

For a CalculatedValue field with elementType: 'boolean' this creates a text mapping with ngram/keyword/sort subfields in the search index. Term queries, aggregations and boolean filters on the field then behave like text search, and the Studio data object grid boolean filter on such a field stops working.

Reproduction

  1. Class definition with a CalculatedValue field configured with elementType: 'boolean'
  2. Run bin/console generic-data-index:update:index
  3. GET <index>/_mapping/field/standard_fields.<fieldname> returns text (with ngram/keyword/sort subfields) instead of boolean

Solution

Add a dedicated CalculatedValueAdapter that maps the field according to its configured element type:

elementType index mapping
boolean boolean
numeric float
date date (strict_date_time_no_millis)
input / textarea / html (default) text/keyword (behavior unchanged)

Values are normalized per element type, since calculators are free to return loosely typed values (e.g. '0'/'1' strings from expression results, which a boolean mapping would reject). For the text-based element types the existing TextKeywordAdapter normalization (base64 src stripping) is preserved.

Covered by unit tests (CalculatedValueAdapterTest). Verified end-to-end on Elasticsearch 8.19: after this change generic-data-index:update:index creates the new index version with a boolean mapping and reindexing succeeds.

Copilot AI balanced review requested due to automatic review settings August 5, 2026 08:21
@pimcore-deployments
pimcore-deployments marked this pull request as draft August 5, 2026 08:21
@pimcore-deployments

Copy link
Copy Markdown
Contributor

🚫 Issue-link guardrail failed — this PR has been converted to draft.

Every PR must reference a tracking issue in pimcore/platform-version so the change stays traceable.

  • No issue in pimcore/platform-version is linked.

Add the link with a keyword in the PR description (not in a comment): https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests

When fixed, press Ready for review to re-run the checks.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Boolean string values such as 'false' are currently normalized to true.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Pull request overview

Adds element-type-aware indexing for calculated values.

Changes:

  • Adds boolean, numeric, date, and text mappings with normalization.
  • Registers the dedicated adapter.
  • Adds unit coverage for mappings and normalization.
File summaries
File Description
CalculatedValueAdapter.php Implements mapping and normalization.
field-definition-adapters.yml Registers the new adapter.
CalculatedValueAdapterTest.php Tests mappings and normalized values.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Balanced

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Comment on lines +82 to +86
if ($value === null || is_bool($value)) {
return $value;
}

return (bool) $value;
Calculated value fields were always mapped as text/keyword regardless of
their configured element type. This made boolean, numeric and date
calculated values unusable for term queries, aggregations and range
filters in the search index.

Add a dedicated CalculatedValueAdapter that maps the field based on the
element type (boolean, numeric, date) and falls back to the existing
text/keyword mapping for the text-based element types (input, textarea,
html). Values are normalized accordingly, since calculators may return
loosely typed values.
A plain bool cast would index the literal 'false' (and values such as
'off'/'no') as true, silently reversing filters. Use FILTER_VALIDATE_BOOLEAN
with FILTER_NULL_ON_FAILURE so unrecognized values become null instead.
@andreaswagner-rnab
andreaswagner-rnab force-pushed the fix/calculated-value-element-type-mapping branch from aae95d9 to abd7cc9 Compare August 5, 2026 09:05
@andreaswagner-rnab
andreaswagner-rnab marked this pull request as ready for review August 5, 2026 09:05
@sonarqubecloud

sonarqubecloud Bot commented Aug 5, 2026

Copy link
Copy Markdown

@astapc
astapc requested a review from mcop1 August 10, 2026 05:16
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.

4 participants