# Custom datatype in mappin

**URL:** <https://discuss.elastic.co/t/custom-datatype-in-mappin/39634>\
**Category:** Elasticsearch\
**Created:** [January 20, 2016, 9:28am UTC](https://discuss.elastic.co/t/custom-datatype-in-mappin/39634 "2016-01-20T09:28:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamynier](https://avatars.discourse-cdn.com/v4/letter/j/ecccb3/32.png) [@jamynier](https://discuss.elastic.co/u/jamynier)\
**Post date:** [January 20, 2016, 9:28am UTC](https://discuss.elastic.co/t/custom-datatype-in-mappin/39634/1 "2016-01-20T09:28:09Z")

</div>

I first post my question/feature request on [https://github.com/elastic/elasticsearch/issues/14341](https://github.com/elastic/elasticsearch/issues/14341)  
but did not get a satisfactory answer.

I haven't found a way to create a custom datatype to reuse in mapping definition.

I would like to have a way to define custom\_datatype in the mapping like that :

```
{
  "settings" : {
     "number_of_shards" : 1,
     "custom_datatypes": [{
         "string_with_raw": {
           "mapping": {
             "index": "analyzed",
             "omit_norms": true,
             "type": "string",
             "fields": {
               "raw": {
                 "ignore_above": 256,
                 "index": "not_analyzed",
                 "type": "string"
               }
             }
           }
         }
      }],
  },
  "mappings" : {
    "my_type": {
      "properties": {
        "field1": {
            "type": "string_with_raw"             
        },
        "field2": {
            "type": "string_with_raw"             
         },
         "field3": {
            "type": "string"             
         }
      }
    }
  }
}

```

For now I have to duplicate for every field :

```
"mappings": {
      "my_type": {      
        "properties": {
          "message": {
               "index": "analyzed",
               "omit_norms": true,
               "type": "string",
               "fields": {
                  "raw": {
                     "ignore_above": 256,
                     "index": "not_analyzed",
                     "type": "string"
                  }
               }     
          },
          "field2": {
              "index": "analyzed",
              "omit_norms": true,
              "type": "string",
              "fields": {
                "raw": {
                  "ignore_above": 256,
                  "index": "not_analyzed",
                  "type": "string"
                }
              }             
          },
          "field3": {
              "type": "string"             
          }
        }
     }
}

```

}

It could also be used in dynamic mappings:

```
{
 "settings" : {
    "number_of_shards" : 1,
    "custom_datatypes": [{
        "string_with_raw": {
          "mapping": {
            "index": "analyzed",
            "omit_norms": true,
            "type": "string",
            "fields": {
              "raw": {
                "ignore_above": 256,
                "index": "not_analyzed",
                "type": "string"
              }
            }
          }
        }
     }],
},
"mappings" : {
  "my_type": {
     "dynamic_templates": [{
        "message_field": {
          "mapping": {
            "omit_norms": false,
           "type": "string_with_raw"
          },
          "match_mapping_type": "string",
          "match": "*_with_raw"
        }
    }],
    "properties": {
      "field1": {
            "type": "string_with_raw"             
        },
       "field2": {
            "type": "string_with_raw"             
        },
        "field3": {
            "type": "string"             
        }            
    }
  }
}

```

}

For the dynamic\_templates part, the value set in the mapping should override equivalent field defined in the custom datatype.

Is there a way to achieve that at the moment ?

---

<div class="post-metadata">

**Author:** ![abeyad](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@abeyad](https://discuss.elastic.co/u/abeyad)\
**Post date:** [January 21, 2016, 1:27am UTC](https://discuss.elastic.co/t/custom-datatype-in-mappin/39634/2 "2016-01-21T01:27:18Z")

</div>

There is currently no way to create custom data types through the JSON settings as you've outlined. However, you can create custom data types by implementing an Elasticsearch Plugin and registering the type that way. This plugin shows an example of how to create a custom datatype:

> **[elastic/elasticsearch-mapper-attachments](https://github.com/elastic/elasticsearch-mapper-attachments)**
>
> elasticsearch-mapper-attachments - Mapper Attachments Type plugin for Elasticsearch

---

<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 5, 2017, 11:22pm UTC](https://discuss.elastic.co/t/custom-datatype-in-mappin/39634/3 "2017-07-05T23:22:48Z")

</div>


