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

The dynamic mapping parameter supports strict_allow_templates #14555

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

gaobinlong
Copy link
Contributor

@gaobinlong gaobinlong commented Jun 26, 2024

Description

This PR adds a new type strict_allow_templates for the dynamic parameter of the index mappings. If strict_allow_templates is used and new detected fields can match the pre-defined dynamic templates in the index mappings, then these fields can be added to the mapping dynamically, if not match, an exception will be thrown: mapping set to strict_allow_templates, dynamic introduction of [test2] within [_doc] is not allowed(same to strict type).

The usage is:

  1. Create an index with setting dynamic to strict_allow_templates
PUT index1
{
  "mappings": {
    "dynamic": "strict_allow_templates",
    "dynamic_templates": [
      {
        "strings": {
          "match": "foo*",
          "match_mapping_type": "string",
          "mapping": {
            "type": "keyword"
          }
        }
      }
    ],
    "properties": {
      "test1": {
        "type": "text"
      }
    }
  }
}
  1. Field test1 exists in the explicit mapping, and field foo can match the dynamic template, so index the document 1 successes.
POST index1/_doc/1
{
  "foo": "1",
  "test1": "test1"
}
  1. Field test2 doesn't exist in the explicit mapping and cannot match the dynamic template, so index the document 2 fails.
POST index1/_doc/2
{
  "foo": "1",
  "test2": "test2"
}

throws:

{
  "error": {
    "root_cause": [
      {
        "type": "strict_dynamic_mapping_exception",
        "reason": "mapping set to strict_allow_templates, dynamic introduction of [test2] within [_doc] is not allowed"
      }
    ],
    "type": "strict_dynamic_mapping_exception",
    "reason": "mapping set to strict_allow_templates, dynamic introduction of [test2] within [_doc] is not allowed"
  },
  "status": 400
}

Related Issues

#11276

Check List

  • Functionality includes testing.
  • API changes companion pull request created, if applicable.
  • Public documentation issue/PR created, if applicable.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Gao Binlong <[email protected]>
Copy link
Contributor

❌ Gradle check result for aa9ab72: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Copy link
Contributor

❌ Gradle check result for ebbc317: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Copy link
Contributor

❌ Gradle check result for bb0e1f8: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant