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

[BUG] Dynamic templates with path_match array don't work because its value is wrongly resolved as string #17027

Open
fs-chris opened this issue Jan 15, 2025 · 0 comments
Labels
bug Something isn't working Other untriaged

Comments

@fs-chris
Copy link

Describe the bug

Dynamic mapping in component templates do not work when using a path_match array.
The path_match array property is wrongly resolved to a string containing the JSON array when being applied to a new index.
I.e.,

...        "path_match": [
              "a.*",
              "b.*"
            ], ...

becomes

...    "path_match": "[a.*, b.*]", ...

which never matches.

Related component

Other

To Reproduce

  1. Create component template with dynamic mapping using a path_match array
PUT _component_template/test
{
  "template": {
    "mappings": {
      "dynamic_templates": [
        {
          "test": {
            "path_match": [
              "a.*",
              "b.*"
            ],
            "mapping": {
              "type": "keyword"
            }
          }
        }
      ]
    }
  }
}
  1. Verify the correctly stored template
GET _component_template/test  
{ 
  "component_templates": [ 
    { 
      "name": "test",
      "component_template": { 
        "template": { 
          "mappings": { 
            "dynamic_templates": [ 
              { 
                "test": { 
                  "path_match": [ 
                    "a.*",
                    "b.*"
                  ],
                  "mapping": { 
                    "type": "keyword"
            ...
  1. Create index template that applies the mapping to test indexes
PUT _index_template/test
{
  "index_patterns": [
    "test*"
  ],
  "composed_of": [
    "test"
  ]
}
  1. Store a document into a test index
PUT test-1/_doc/1
{
  "a": {
    "x": "Hello"
  },
  "b": {
    "y": "world"
  }
}
  1. Check the mapping of the newly created index
    -> the path_match property is wrongly stored as single string
    -> the intended dynamic mapping was not applied to the properties; instead the properties are defined with the default type text (and keyword sub-field).
GET test-1/_mapping
{ 
  "test-1": { 
    "mappings": { 
      "dynamic_templates": [ 
        { 
          "test": { 
            "path_match": "[a.*, b.*]",
            "mapping": { 
              "type": "keyword"
            }
          }
        }
      ],
      "properties": { 
        "a": { 
          "properties": { 
            "x": { 
              "type": "text",
              "fields": { 
                "keyword": { 
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            }
          }
        },
        "b": { 
          "properties": { 
            "y": { 
              "type": "text",
              "fields": { 
                "keyword": { 
                  "type": "keyword",
                  "ignore_above": 256
                }
       ...

Expected behavior

The JSON array containing separate match patterns should be preserved when applying the template to a new index.

Additional Details

Plugins
none

Screenshots
n/a

Host/Environment (please complete the following information):

  • OpenSearch 2.17.1 (Docker image)

Additional context
n/a

@fs-chris fs-chris added bug Something isn't working untriaged labels Jan 15, 2025
@github-actions github-actions bot added the Other label Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Other untriaged
Projects
None yet
Development

No branches or pull requests

1 participant