Skip to content

Fix generation of dynamic mapping for object with specific subfield#204104

Merged
jsoriano merged 4 commits intoelastic:mainfrom
jsoriano:dynamic-mapping-non-empty-object
Dec 16, 2024
Merged

Fix generation of dynamic mapping for object with specific subfield#204104
jsoriano merged 4 commits intoelastic:mainfrom
jsoriano:dynamic-mapping-non-empty-object

Conversation

@jsoriano
Copy link
Copy Markdown
Member

@jsoriano jsoriano commented Dec 12, 2024

Summary

Fix generation of dynamic mapping for objects that have more specific subfields in separate definitions.

This can be reproduced for example with:

- name: labels
  type: object
  object_type: keyword
  object_type_mapping_type: '*'
- name: labels.count
  type: long

Fleet expands and deduplicates field definitions before generating the mappings, so the definitions above are converted to something like the following:

- name: labels
  type: group
  object_type: keyword
  object_type_mapping_type: '*'
  fields:
  - name: count
    type: long

Usually fields of type group don't have an object_type, so this was being ignored, the dynamic mapping was not being generated.

This issue was not reproduced if the object field name includes a wildcard, like in labels.*, because then the expansion and deduplication resolves to something like this:

- name: labels
  type: group
  fields:
  - name: '*'
    type: object
    object_type: keyword
    object_type_mapping_type: '*'
  - name: count
    type: long

Checklist

  • Unit or functional tests were updated or added to match the most common scenarios
  • Flaky Test Runner was used on any tests changed
  • The PR description includes the appropriate Release Notes section, and the correct release_note:* label is applied per the guidelines

Identify risks

@jsoriano jsoriano self-assigned this Dec 12, 2024
@jsoriano jsoriano requested a review from a team as a code owner December 12, 2024 18:25
@botelastic botelastic bot added the Team:Fleet Team label for Observability Data Collection Fleet team label Dec 12, 2024
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/fleet (Team:Fleet)

- name: labels.count
type: long
`;
const objectFieldWithPropertyReversedMapping = {
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.

should there be a test with group type?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The group type cannot have object_type. Only internally in fleet after the deduplication.

Copy link
Copy Markdown
Contributor

@juliaElastic juliaElastic left a comment

Choose a reason for hiding this comment

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

Code LGTM

@jsoriano jsoriano enabled auto-merge (squash) December 16, 2024 19:21
@jsoriano jsoriano merged commit e3877e0 into elastic:main Dec 16, 2024
@kibanamachine
Copy link
Copy Markdown
Contributor

Starting backport for target branches: 8.16, 8.17, 8.x

https://github.com/elastic/kibana/actions/runs/12361165154

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

cc @jsoriano

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Dec 16, 2024
…lastic#204104)

Fix generation of dynamic mapping for objects that have more specific
subfields in separate definitions.

This can be reproduced for example with:
```
- name: labels
  type: object
  object_type: keyword
  object_type_mapping_type: '*'
- name: labels.count
  type: long
```

Fleet expands and deduplicates field definitions before generating the
mappings, so the definitions above are converted to something like the
following:
```
- name: labels
  type: group
  object_type: keyword
  object_type_mapping_type: '*'
  fields:
  - name: count
    type: long
```

Usually fields of type `group` don't have an `object_type`, so this was
being ignored, the dynamic mapping was not being generated.

This issue was not reproduced if the object field name includes a
wildcard, like in `labels.*`, because then the expansion and
deduplication resolves to something like this:
```
- name: labels
  type: group
  fields:
  - name: '*'
    type: object
    object_type: keyword
    object_type_mapping_type: '*'
  - name: count
    type: long
```

(cherry picked from commit e3877e0)
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Dec 16, 2024
…lastic#204104)

Fix generation of dynamic mapping for objects that have more specific
subfields in separate definitions.

This can be reproduced for example with:
```
- name: labels
  type: object
  object_type: keyword
  object_type_mapping_type: '*'
- name: labels.count
  type: long
```

Fleet expands and deduplicates field definitions before generating the
mappings, so the definitions above are converted to something like the
following:
```
- name: labels
  type: group
  object_type: keyword
  object_type_mapping_type: '*'
  fields:
  - name: count
    type: long
```

Usually fields of type `group` don't have an `object_type`, so this was
being ignored, the dynamic mapping was not being generated.

This issue was not reproduced if the object field name includes a
wildcard, like in `labels.*`, because then the expansion and
deduplication resolves to something like this:
```
- name: labels
  type: group
  fields:
  - name: '*'
    type: object
    object_type: keyword
    object_type_mapping_type: '*'
  - name: count
    type: long
```

(cherry picked from commit e3877e0)
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Dec 16, 2024
…lastic#204104)

Fix generation of dynamic mapping for objects that have more specific
subfields in separate definitions.

This can be reproduced for example with:
```
- name: labels
  type: object
  object_type: keyword
  object_type_mapping_type: '*'
- name: labels.count
  type: long
```

Fleet expands and deduplicates field definitions before generating the
mappings, so the definitions above are converted to something like the
following:
```
- name: labels
  type: group
  object_type: keyword
  object_type_mapping_type: '*'
  fields:
  - name: count
    type: long
```

Usually fields of type `group` don't have an `object_type`, so this was
being ignored, the dynamic mapping was not being generated.

This issue was not reproduced if the object field name includes a
wildcard, like in `labels.*`, because then the expansion and
deduplication resolves to something like this:
```
- name: labels
  type: group
  fields:
  - name: '*'
    type: object
    object_type: keyword
    object_type_mapping_type: '*'
  - name: count
    type: long
```

(cherry picked from commit e3877e0)
@kibanamachine
Copy link
Copy Markdown
Contributor

💚 All backports created successfully

Status Branch Result
8.16
8.17
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Dec 17, 2024
@kibanamachine
Copy link
Copy Markdown
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

1 similar comment
@kibanamachine
Copy link
Copy Markdown
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

JoseLuisGJ pushed a commit to JoseLuisGJ/kibana that referenced this pull request Dec 19, 2024
…lastic#204104)

Fix generation of dynamic mapping for objects that have more specific
subfields in separate definitions.

This can be reproduced for example with:
```
- name: labels
  type: object
  object_type: keyword
  object_type_mapping_type: '*'
- name: labels.count
  type: long
```

Fleet expands and deduplicates field definitions before generating the
mappings, so the definitions above are converted to something like the
following:
```
- name: labels
  type: group
  object_type: keyword
  object_type_mapping_type: '*'
  fields:
  - name: count
    type: long
```

Usually fields of type `group` don't have an `object_type`, so this was
being ignored, the dynamic mapping was not being generated.

This issue was not reproduced if the object field name includes a
wildcard, like in `labels.*`, because then the expansion and
deduplication resolves to something like this:
```
- name: labels
  type: group
  fields:
  - name: '*'
    type: object
    object_type: keyword
    object_type_mapping_type: '*'
  - name: count
    type: long
```
@kibanamachine
Copy link
Copy Markdown
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

12 similar comments
@kibanamachine
Copy link
Copy Markdown
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

@kibanamachine
Copy link
Copy Markdown
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

@kibanamachine
Copy link
Copy Markdown
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

@kibanamachine
Copy link
Copy Markdown
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

@kibanamachine
Copy link
Copy Markdown
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

@kibanamachine
Copy link
Copy Markdown
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

@kibanamachine
Copy link
Copy Markdown
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

@kibanamachine
Copy link
Copy Markdown
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

@kibanamachine
Copy link
Copy Markdown
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

@kibanamachine
Copy link
Copy Markdown
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

@kibanamachine
Copy link
Copy Markdown
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

@kibanamachine
Copy link
Copy Markdown
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

jsoriano added a commit that referenced this pull request Jan 8, 2025
…ield (#204104) (#204493)

# Backport

This will backport the following commits from `main` to `8.x`:
- [Fix generation of dynamic mapping for object with specific subfield
(#204104)](#204104)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Jaime Soriano
Pastor","email":"jaime.soriano@elastic.co"},"sourceCommit":{"committedDate":"2024-12-16T20:58:30Z","message":"Fix
generation of dynamic mapping for object with specific subfield
(#204104)\n\nFix generation of dynamic mapping for objects that have
more specific\r\nsubfields in separate definitions.\r\n\r\nThis can be
reproduced for example with:\r\n```\r\n- name: labels\r\n type:
object\r\n object_type: keyword\r\n object_type_mapping_type: '*'\r\n-
name: labels.count\r\n type: long\r\n```\r\n\r\nFleet expands and
deduplicates field definitions before generating the\r\nmappings, so the
definitions above are converted to something like
the\r\nfollowing:\r\n```\r\n- name: labels\r\n type: group\r\n
object_type: keyword\r\n object_type_mapping_type: '*'\r\n fields:\r\n -
name: count\r\n type: long\r\n```\r\n\r\nUsually fields of type `group`
don't have an `object_type`, so this was\r\nbeing ignored, the dynamic
mapping was not being generated.\r\n\r\nThis issue was not reproduced if
the object field name includes a\r\nwildcard, like in `labels.*`,
because then the expansion and\r\ndeduplication resolves to something
like this:\r\n```\r\n- name: labels\r\n type: group\r\n fields:\r\n -
name: '*'\r\n type: object\r\n object_type: keyword\r\n
object_type_mapping_type: '*'\r\n - name: count\r\n type:
long\r\n```","sha":"e3877e053405bae71b5576648cb7c637c4a23f9a","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Fleet","v9.0.0","backport:prev-major"],"title":"Fix
generation of dynamic mapping for object with specific
subfield","number":204104,"url":"https://github.com/elastic/kibana/pull/204104","mergeCommit":{"message":"Fix
generation of dynamic mapping for object with specific subfield
(#204104)\n\nFix generation of dynamic mapping for objects that have
more specific\r\nsubfields in separate definitions.\r\n\r\nThis can be
reproduced for example with:\r\n```\r\n- name: labels\r\n type:
object\r\n object_type: keyword\r\n object_type_mapping_type: '*'\r\n-
name: labels.count\r\n type: long\r\n```\r\n\r\nFleet expands and
deduplicates field definitions before generating the\r\nmappings, so the
definitions above are converted to something like
the\r\nfollowing:\r\n```\r\n- name: labels\r\n type: group\r\n
object_type: keyword\r\n object_type_mapping_type: '*'\r\n fields:\r\n -
name: count\r\n type: long\r\n```\r\n\r\nUsually fields of type `group`
don't have an `object_type`, so this was\r\nbeing ignored, the dynamic
mapping was not being generated.\r\n\r\nThis issue was not reproduced if
the object field name includes a\r\nwildcard, like in `labels.*`,
because then the expansion and\r\ndeduplication resolves to something
like this:\r\n```\r\n- name: labels\r\n type: group\r\n fields:\r\n -
name: '*'\r\n type: object\r\n object_type: keyword\r\n
object_type_mapping_type: '*'\r\n - name: count\r\n type:
long\r\n```","sha":"e3877e053405bae71b5576648cb7c637c4a23f9a"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/204104","number":204104,"mergeCommit":{"message":"Fix
generation of dynamic mapping for object with specific subfield
(#204104)\n\nFix generation of dynamic mapping for objects that have
more specific\r\nsubfields in separate definitions.\r\n\r\nThis can be
reproduced for example with:\r\n```\r\n- name: labels\r\n type:
object\r\n object_type: keyword\r\n object_type_mapping_type: '*'\r\n-
name: labels.count\r\n type: long\r\n```\r\n\r\nFleet expands and
deduplicates field definitions before generating the\r\nmappings, so the
definitions above are converted to something like
the\r\nfollowing:\r\n```\r\n- name: labels\r\n type: group\r\n
object_type: keyword\r\n object_type_mapping_type: '*'\r\n fields:\r\n -
name: count\r\n type: long\r\n```\r\n\r\nUsually fields of type `group`
don't have an `object_type`, so this was\r\nbeing ignored, the dynamic
mapping was not being generated.\r\n\r\nThis issue was not reproduced if
the object field name includes a\r\nwildcard, like in `labels.*`,
because then the expansion and\r\ndeduplication resolves to something
like this:\r\n```\r\n- name: labels\r\n type: group\r\n fields:\r\n -
name: '*'\r\n type: object\r\n object_type: keyword\r\n
object_type_mapping_type: '*'\r\n - name: count\r\n type:
long\r\n```","sha":"e3877e053405bae71b5576648cb7c637c4a23f9a"}}]}]
BACKPORT-->

Co-authored-by: Jaime Soriano Pastor <jaime.soriano@elastic.co>
@kibanamachine kibanamachine added v8.18.0 and removed backport missing Added to PRs automatically when the are determined to be missing a backport. labels Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release_note:fix Team:Fleet Team label for Observability Data Collection Fleet team v8.18.0 v9.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants