mirror of
https://github.com/elastic/kibana.git
synced 2025-06-27 18:51:07 -04:00
Document that index/enable: false SO mappings is an anti-pattern (#201969)
## Summary Document that index/enable: false SO mappings is an anti-pattern ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) 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](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) ### Identify risks Does this PR introduce any risks? For example, consider risks like hard to test bugs, performance regression, potential of data loss. Describe the risk, its severity, and mitigation for each identified risk. Invite stakeholders and evaluate how to proceed before merging. - [ ] [See some risk examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) - [ ] ...
This commit is contained in:
parent
721b4beb1a
commit
5f639b2a07
1 changed files with 50 additions and 0 deletions
|
@ -126,6 +126,56 @@ Do not use field mappings like you would use data types for the columns of a SQL
|
|||
SQL index. Only specify field mappings for the fields you wish to search on or query. By specifying `dynamic: false`
|
||||
in any level of your mappings, Elasticsearch will accept and store any other fields even if they are not specified in your mappings.
|
||||
|
||||
Never use `enabled: false` or `index: false` in your mappings. Elasticsearch does not support toggling these mapping options, so if
|
||||
your plugin ever needs to query the data, you will not be able to do so. Since these fields cannot be queried, they would require
|
||||
migrating to a new field and making associated code changes. Instead, use `dynamic: false` which provides the same flexibility while
|
||||
maintaining the future ability to query fields if necessary.
|
||||
|
||||
Here's an example of what NOT to do:
|
||||
|
||||
```ts
|
||||
export const dashboardVisualization: SavedObjectsType = {
|
||||
name: 'dashboard_visualization',
|
||||
...
|
||||
mappings: {
|
||||
properties: {
|
||||
metadata: {
|
||||
enabled: false, // ❌ Don't do this
|
||||
properties: {
|
||||
created_by: { type: 'keyword' }
|
||||
}
|
||||
},
|
||||
description: {
|
||||
index: false, // ❌ Don't do this
|
||||
type: 'text'
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
Instead, use `dynamic: false` if you want to persist data which does not need to be queryable.
|
||||
```ts
|
||||
export const dashboardVisualization: SavedObjectsType = {
|
||||
name: 'dashboard_visualization',
|
||||
...
|
||||
mappings: {
|
||||
properties: {
|
||||
dynamic: false, // ✅ Do this instead
|
||||
metadata: {
|
||||
// dynamic: false gets inherited from above
|
||||
properties: {
|
||||
// `created_by` can now be stored but won't be queryable
|
||||
}
|
||||
},
|
||||
// `description` can now be stored but won't be queryable
|
||||
}
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
This approach maintains flexibility while ensuring all fields remain queryable if needed in the future.
|
||||
|
||||
Since Elasticsearch has a default limit of 1000 fields per index, plugins should carefully consider the
|
||||
fields they add to the mappings. Similarly, Saved Object types should never use `dynamic: true` as this can cause an arbitrary
|
||||
amount of fields to be added to the .kibana index.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue