Skip to content

Conversation

@martijnvg
Copy link
Member

@martijnvg martijnvg commented Nov 19, 2025

If StoredFieldsSpec requires source and has no sourcePaths, then it requires the whole source. For example, in case of SourceFieldBlockLoader. When merging StoredFieldsSpec then omit the sourcePaths of the other StoredFieldsSpec.

Closes #138188

(a non released issue)

If StoredFieldsSpec requires source and has no sourcePaths, then it requires the whole source. For example, in case of `SourceFieldBlockLoader`. When merging StoredFieldsSpec then omit the sourcePaths of the other StoredFieldsSpec.

Closes elastic#138188
@martijnvg martijnvg added :StorageEngine/Mapping The storage related side of mappings >non-issue labels Nov 20, 2025
@martijnvg martijnvg marked this pull request as ready for review November 20, 2025 12:45
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-storage-engine (Team:StorageEngine)

mergedSourcePaths.addAll(other.sourcePaths);
} else if (this.sourcePaths.isEmpty() == false) {
mergedSourcePaths = this.sourcePaths;
if (other.requiresSource) {

Choose a reason for hiding this comment

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

Ah! So our intuition was right - every time we apply the filter, we are stripping down the rest of the source. The fix is to always keep the source if it's been asked for

Copy link

@quackaplop quackaplop Nov 21, 2025

Choose a reason for hiding this comment

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

As a side note, there seems to be quite a bit of boiler plate in this method, with some repeated outcomes. Do we want to shove them into separate tiny inlinable functions?

Copy link
Member Author

Choose a reason for hiding this comment

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

Let me see if that actually makes to code cleaner.

index: my-index2
body:
mappings:
dynamic: false

Choose a reason for hiding this comment

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

Is this important? The dynamic I mean

Copy link
Member Author

@martijnvg martijnvg Nov 21, 2025

Choose a reason for hiding this comment

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

For the query being tested here, yes. Otherwise the test wouldn't fail.
The FROM my-index2 METADATA _source | LIMIT 10 requests all mapped fields, but because baz isn't mapped without the fix to StoredFieldSpec, we would filter it out. If the baz field was mapped, the stored field spec of the other column would include it in the final stored field spec.

- do:
esql.query:
body:
query: 'FROM my-index2 METADATA _source | LIMIT 10'
Copy link

@quackaplop quackaplop Nov 21, 2025

Choose a reason for hiding this comment

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

Not to be annoying, but are we testing here with what we actually want to be testing?

Here we seem to have an index with a single text field, so even if we had not fixed the bug, I think this still would've worked, right - we would've stripped the source of everything but the field, which doesn't actually change the _source.

Feels like we need the mapping with at least one another field, and the query that reads the entire source and the text field. We should be testing that the filtered out field is still returned in source

This thing - #138188 - has the correctly shaped example I think.

Copy link
Member Author

Choose a reason for hiding this comment

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

Here we seem to have an index with a single text field, so even if we had not fixed the bug, I think this still would've worked, right - we would've stripped the source of everything but the field, which doesn't actually change the _source.

Without the fix to StoredFieldSpec this test fails.

I can add a @timestamp field, but that doesn't change the outcome of the test.

@quackaplop
Copy link

Also on the (a non released issue) - this has been out in Serverless all this time, so sadly customers have been exposed to this. I don't know if it's changing much in terms of the path forward though

spec = spec.merge(
new StoredFieldsSpec(
true,
false,

Choose a reason for hiding this comment

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

So this may be silly question, but it seems like we very much changed the meaning of this test, right? The way I read this, we changed requiresSource to false, which - in some sense - triggers the "pre-bug" behavior. This makes sense.
Should we add a mirror test with this flag set to true?

Copy link
Member Author

Choose a reason for hiding this comment

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

The test just walks through a few scenarios and I just appended the scenario that triggered the bug. I can add a dedicated unit test for the bug here.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ES|QL: METADATA _source doesn't work with text fields

3 participants