Skip to content
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

Include runtime fields in total fields count #89251

Merged

Conversation

mayya-sharipova
Copy link
Contributor

We have a check that enforces the total number of fields needs to be below a
certain (configurable) threshold. Before runtime fields did not contribute
to the count. This patch makes all runtime fields contribute to the
count, runtime fields:

  • that were explicitly defined in mapping by a user
  • as well as runtime fields that were dynamically created by dynamic
    mappings

Closes #88265

We have a check that enforces the total number of fields needs to be below a
certain (configurable) threshold. Before runtime fields did not contribute
to the count. This patch makes all runtime fields contribute to the
count, runtime fields:
- that were explicitly defined in mapping by a user
- as well as runtime fields that were dynamically created by dynamic
 mappings

Closes elastic#88265
@mayya-sharipova mayya-sharipova added :Search Foundations/Mapping Index mappings, including merging and defining field types v8.5.0 >bug labels Aug 10, 2022
@elasticsearchmachine elasticsearchmachine added the Team:Search Meta label for search team label Aug 10, 2022
@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine
Copy link
Collaborator

Hi @mayya-sharipova, I've created a changelog YAML for you.

Copy link
Member

@javanna javanna left a comment

Choose a reason for hiding this comment

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

I left a couple of comments. I also wonder if we should make the error message clearer and return the count of new fields, and even say how many objects, how many mappers and how many runtime fields are being added. That can be a followup though

// note that existing fields can also receive dynamic mapping updates (e.g. constant_keyword to fix the value)
if (mappingLookup.getMapper(fieldName) == null
&& mappingLookup.objectMappers().containsKey(fieldName) == false
&& newFieldsSeen.add(fieldName)) {
Copy link
Member

Choose a reason for hiding this comment

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

I had to catch up on the existing logic and why we need to check that the mapper does not exist: don't we call this method only for new fields? There is actually a chance that existing fields receive dynamic updates, it's all in the comment above ( note that existing fields can also receive dynamic mapping updates).

When we are adding a dynamic runtime field these these two checks are redundant, because they will always return false? Do we want to have two different codepaths then for the two scenarios? Though I would not add a check that the runtime field does not yet exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, based on the comments, since existing mappers can receive mapping updates, we needed this check.

When we are adding a dynamic runtime field these these two checks are redundant, because they will always return false? Do we want to have two different codepaths then for the two scenarios?

Thanks for explaining this, I did not know this. I've made the tow different codepaths in 1ee4270

@mayya-sharipova
Copy link
Contributor Author

@javanna Thanks for the initial review. I've tried to address in 1ee4270

I also wonder if we should make the error message clearer and return the count of new fields, and even say how many objects, how many mappers and how many runtime fields are being added. That can be a followup though

I am happy to add extra info in the error message as a part of this PR. I wonder if this constitutes a breaking change, or we are fine to change to expand error messages?

Copy link
Member

@javanna javanna left a comment

Choose a reason for hiding this comment

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

left two nits, looks great though, thanks a lot for working on this! Let's iterate on the error message as a follow-up.

@@ -279,6 +279,9 @@ final ObjectMapper getDynamicObjectMapper(String name) {
* Add a new runtime field dynamically created while parsing.
*/
public final void addDynamicRuntimeField(RuntimeField runtimeField) {
if (newFieldsSeen.add(runtimeField.name())) {
Copy link
Member

Choose a reason for hiding this comment

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

A runtime field can have the same name as an indexed field, in which case it will shadow the indexed field at search time. I wondered if it's ok to have the same set for both runtime fields and indexed fields and it does look ok because when it comes to dynamic mappings, when we encounter a new field, either we map it as a runtime field or as an indexed field, and never both, so there are never going to be collisions. Shall we add a comment to clarify that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@javanna Good suggestion, addressed in dbf2022

Indeed for dynamic updates, a field can be mapped either as runtime field or as indexed field, so no problem here.

For PUT _mapping updates, a user can introduce a new runtime field with the same name as existing indexed field. In this case, this new runtime field will be added to the total count, and can cause an exception for total field counts.

@mayya-sharipova mayya-sharipova force-pushed the runtime-fields-total-count branch from 69582cf to dbf2022 Compare August 12, 2022 14:11
@mayya-sharipova mayya-sharipova merged commit 10b8047 into elastic:main Aug 15, 2022
@mayya-sharipova mayya-sharipova deleted the runtime-fields-total-count branch August 15, 2022 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Search Meta label for search team v8.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Include runtime fields in total fields count
3 participants