Skip to content

Adds transport-only flag to always include indices in the field caps transport response #133074

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

piergm
Copy link
Member

@piergm piergm commented Aug 18, 2025

When calling field_caps with an expression that resolves to 2+ indices we currently return in the field caps response on a per-field basis the index where that particular field was found only if there is a mapping conflict (eg: index1 field foo is text and in index2 field foo is a long).
With the following change we allow internal users of the FieldCaps action to set includeIndices a boolean flag that if set to true will always return the indices array.
This allows FieldCaps internal consumers to understand on which indices a certain field was found.
Let's say we have two indices: "index1" with mapping foo1=keyword and foo2=keyword and "index2" with mapping foo2=keyword.
Then when requesting GET index*/_field_caps?fields=* with includeIndices set to true, the field caps response will be:

...
"foo1": {
            "keyword": {
                ...
                "indices": [
                    "index1"<---------------------- ADDS THIS
                ]
            },
"foo2": {
            "keyword": {
                ...
                "indices": [
                    "index1", "index2"<---------------------- ADDS THIS
                ]
            }
...

Note: With includeIndices==false we keep the current behaviour to return "indices" only if there is a mapping conflict.

@piergm piergm self-assigned this Aug 18, 2025
@piergm piergm added :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch v9.2.0 labels Aug 18, 2025
@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine
Copy link
Collaborator

Hi @piergm, I've created a changelog YAML for you.

@piergm piergm requested review from idegtiarenko and javanna August 19, 2025 07:51
Copy link
Contributor

@benchaplin benchaplin left a comment

Choose a reason for hiding this comment

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

Cool change :)

@@ -53,6 +53,7 @@ public final class FieldCapabilitiesRequest extends LegacyActionRequest implemen
private String[] types = Strings.EMPTY_ARRAY;
private boolean includeUnmapped = false;
private boolean includeEmptyFields = true;
private boolean includeIndices = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't this need to be added to the writeTo method and the StreamInput constructor? I'm a bit confused how the tests are passing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Generally I think one of the two things should happen:

  1. It is added to the serializations as you noted above, and we have TransportVersion bumped.
  2. It's not serialized and then marked transient and a comment is added as to why we don't need to serialize it.

In this particular case I think we do need to serialize it so (1) should happen.

Copy link
Contributor

@idegtiarenko idegtiarenko Aug 19, 2025

Choose a reason for hiding this comment

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

Also should it be added to equals/hashCode? And to corresponding createTestInstance/mutateInstance in FieldCapabilitiesRequestTests (I think it should).
If/when the new flag is added to equality check we might also have to serialize it in order to fix AbstractWireSerializingTestCase

Copy link
Member Author

@piergm piergm Aug 20, 2025

Choose a reason for hiding this comment

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

Hey!

Doesn't this need to be added to the writeTo method and the StreamInput constructor? I'm a bit confused how the tests are passing.

No need to serialize it since we are already sending the indices information that are currently used only for mapping conflicts.

It's not serialized and then marked transient and a comment is added as to why we don't need to serialize it.

++ on this

Copy link
Contributor

@idegtiarenko idegtiarenko left a comment

Choose a reason for hiding this comment

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

Thanks! This looks good from es|ql client view.

@piergm piergm merged commit 18286be into elastic:main Aug 21, 2025
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch v9.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants