# Mapping: setup type by path

**URL:** <https://discuss.elastic.co/t/mapping-setup-type-by-path/68668>\
**Category:** Elasticsearch\
**Created:** [December 12, 2016, 7:48am UTC](https://discuss.elastic.co/t/mapping-setup-type-by-path/68668 "2016-12-12T07:48:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![enp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/enp/32/3825_2.png) [@enp](https://discuss.elastic.co/u/enp)\
**Post date:** [December 12, 2016, 7:48am UTC](https://discuss.elastic.co/t/mapping-setup-type-by-path/68668/1 "2016-12-12T07:48:38Z")

</div>

Hi,

I tried to setup explicit mapping by path:

```
PUT x
{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0
  },
  "mappings": {
    "relevance": {
      "dynamic_templates": [
        {
          "relevance": {
            "path_match": "*.relevance",
            "mapping": {
              "type": "text"
            }
          }
        }
      ]
    }
  }
}

```

But no success:

```
PUT x/x/0
{
  "name": "X",
  "metrics" : {
    "relevance" : 0
  }
}

```

`GET /x/_mapping`

```
{
  "x": {
    "mappings": {
      "relevance": {
        "dynamic_templates": [
          {
            "relevance": {
              "path_match": "*.relevance",
              "mapping": {
                "type": "text"
              }
            }
          }
        ]
      },
      "x": {
        "properties": {
          "metrics": {
            "properties": {
              "relevance": {
                "type": "long"
              }
            }
          },
          "name": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        }
      }
    }
  }
}

```

Som why I see relevance field as long?

---

<div class="post-metadata">

**Author:** ![johtani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johtani/32/44956_2.png) [@johtani](https://discuss.elastic.co/u/johtani)\
**Post date:** [December 12, 2016, 9:15am UTC](https://discuss.elastic.co/t/mapping-setup-type-by-path/68668/2 "2016-12-12T09:15:41Z")

</div>

Your `dynamic_templates` affect under `relevance` type data only.  
You index data as `x/x/0` that this means "x" index and "x" type and "0" id.  
And your `relevance` field is long in JSON, [elasticsearch decide field type from JSON type](https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-field-mapping.html#dynamic-field-mapping).

If you want to use "dynamic\_templates" to all types, you can use [`_default_` mapping.](https://www.elastic.co/guide/en/elasticsearch/reference/current/default-mapping.html)

---

<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:** [January 9, 2017, 9:15am UTC](https://discuss.elastic.co/t/mapping-setup-type-by-path/68668/3 "2017-01-09T09:15:44Z")

</div>

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