Skip to content

Conversation

@natea
Copy link

@natea natea commented Aug 15, 2025

Summary

This PR fixes issue #109797 where the _field_caps API incorrectly returns object and nested fields when using the types parameter, even when those types are not included in the filter.

Problem

When requesting specific field types using the types parameter (e.g., types=text), the API was incorrectly including parent object fields if they had child fields matching the requested type. This behavior was inconsistent with the documented API behavior.

Example

// Index mapping
{
  "properties": {
    "product": {
      "type": "object",
      "properties": {
        "name": { "type": "text" },
        "price": { "type": "float" }
      }
    }
  }
}

// Request: GET /index/_field_caps?fields=*&types=text

// Before (incorrect): Returns both product.name AND product
// After (correct): Returns only product.name

Solution

Modified the parent object inclusion logic in FieldCapabilitiesFetcher.java to respect the types filter. Parent object/nested fields are now only included if their type is explicitly requested in the types parameter.

Changes

  • FieldCapabilitiesFetcher.java: Added types filter check before including parent object fields (lines 210-215)
  • FieldCapabilitiesTypesFilterTests.java: Added comprehensive unit tests covering various scenarios
  • 60_types_filter_objects.yml: Added REST API tests to verify correct behavior

Testing

  • ✅ All existing field capabilities tests pass
  • ✅ Added 5 unit test methods covering different filter combinations
  • ✅ Added 6 REST API test scenarios
  • ✅ Tests verify object/nested fields are excluded when not in types filter
  • ✅ Tests verify object/nested fields are included when explicitly requested

Related Issues

Fixes #109797

Checklist

  • I have signed the Contributor License Agreement
  • I have run the tests locally and they pass
  • I have added tests that prove my fix is effective
  • I have added necessary documentation (API behavior is now consistent with docs)
  • My changes follow the existing code style

🤖 Generated with Claude Code

Co-Authored-By: Claude [email protected]

natea and others added 2 commits August 15, 2025 10:20
…stic#112812)

This change adds validation to detect when copy_to targets a non-existent
field when dynamic mappings are disabled (dynamic=false). Previously, this
configuration would silently fail to copy values at runtime.

Changes:
- Added validation in FieldMapper.validate() to check if copy_to target
  fields exist when dynamic=false
- Throws IllegalArgumentException with clear error message when validation fails
- Added comprehensive unit tests covering the new validation logic

The validation only applies when dynamic=false since other dynamic settings
(true, strict, runtime) have different behaviors for handling unknown fields.

Closes elastic#112812

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
…er (elastic#109797)

When using the `types` parameter with the _field_caps API, object and nested
fields were incorrectly being included in the response when they had child
fields matching the requested types. This fix ensures that parent object
fields are only included when their type (object/nested) is explicitly
requested in the types filter.

Changes:
- Modified FieldCapabilitiesFetcher.java to apply types filter to parent objects
- Added comprehensive unit tests in FieldCapabilitiesTypesFilterTests.java
- Added REST API tests in 60_types_filter_objects.yml

The fix properly filters parent object inclusion based on the types parameter,
ensuring the API only returns fields with the exact types specified.

Fixes elastic#109797

🤖 Generated with Claude Code

Co-Authored-By: Claude <[email protected]>
@elasticsearchmachine elasticsearchmachine added external-contributor Pull request authored by a developer outside the Elasticsearch team v9.2.0 needs:triage Requires assignment of a team area label labels Aug 15, 2025
Exclude .claude-flow/, .swarm/ directories and temporary test/analysis files
from version control to keep the repository clean.
@szybia szybia added :Search Foundations/Mapping Index mappings, including merging and defining field types and removed needs:triage Requires assignment of a team area label labels Aug 18, 2025
@elasticsearchmachine elasticsearchmachine added the Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch label Aug 18, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search-foundations (Team:Search Foundations)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external-contributor Pull request authored by a developer outside the Elasticsearch team :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch v9.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_field_caps with types query parameter returns also objects types if it's a parent of a requested type

3 participants