# Dynamic templates - Any way of accessing a field full path instead of its name?

**URL:** https://discuss.elastic.co/t/dynamic-templates-any-way-of-accessing-a-field-full-path-instead-of-its-name/237774
**Category:** Elasticsearch
**Created:** [June 19, 2020, 9:29am UTC](https://discuss.elastic.co/t/dynamic-templates-any-way-of-accessing-a-field-full-path-instead-of-its-name/237774 "2020-06-19T09:29:31Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![ng.software.dev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ng.software.dev/32/70692_2.png) [@ng.software.dev](https://discuss.elastic.co/u/ng.software.dev)
#### Post date: [June 19, 2020, 9:29am UTC](https://discuss.elastic.co/t/dynamic-templates-any-way-of-accessing-a-field-full-path-instead-of-its-name/237774/1 "2020-06-19T09:29:32Z")

</div>

Hi,

I am developping a search engine in which I rely quite heavily on _dynamic templates_, as the underlying data model is dynamic. So I'm using _path\_match_ with regular expressions.

Here's a sample example to get an idea:

```auto
{
  "mappings": {
    "doc": {
      "dynamic": true,
      "dynamic_templates": [
        {
          "fulltext_search_field_A": {
            "match_pattern": "regex",
            "path_match": "text.field_A\\.value",
            "mapping": {
              "type": "keyword",
              "ignore_above": "32766",
              "copy_to": "@fulltext.text.field_A",
              "fields": { ... }
            }
          }
        },
        ...
        {
          "fulltext_search_field_Z": {
            "match_pattern": "regex",
            "path_match": "text.field_Z\\.value",
            "mapping": {
              "type": "keyword",
              "ignore_above": "32766",
              "copy_to": "@fulltext.text.field_Z",
              "fields": { ... }
            }
          }
        }
      ]
    }
  }
}

```

I need to copy to distinct fields, so in my query I can choose a subset of fields to match, and also I can get a per-field highlighting. The _copy\_to_ target fields are handled by a separate template.

This method works but has issues: the number of fields can be high and this leads to a much bigger cluster state, which can lead to some nasty issues on a shared cluster. For this reason, and for the sake of clarity, I'd like to keep the definitions as succinct as possible.

Moreover, the _mapping_ and _fields_ definitions being the same for all fields, I'd very much like to factorize these into a single dynamic template, so I tried the following:

```auto
{
  "mappings": {
    "doc": {
      "dynamic": true,
      "dynamic_templates": [
        {
          "fulltext_search_fields": {
            "match_pattern": "regex",
            "path_match": "text.field_(?:A|B|...|Z).value",
              "mapping": {
              "type": "keyword",
              "ignore_above": "32766",
              "copy_to": "@fulltext.text.{name}",
              "fields": { ... }
            }
          }
        }
      ]
    }
  }
}

```

Unfortunatey that doesn't work as expected as all my fields get copied over to a single _@fulltext.text.value_ field! What I'd need here is the field's full path instead of just its name!

The reference doc does not mention it, but Is there a means to achieve this? It would be so useful!

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 17, 2020, 9:29am UTC](https://discuss.elastic.co/t/dynamic-templates-any-way-of-accessing-a-field-full-path-instead-of-its-name/237774/2 "2020-07-17T09:29:32Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
