# NEST: Specify type name on mapping

**URL:** <https://discuss.elastic.co/t/nest-specify-type-name-on-mapping/57689>\
**Category:** Elasticsearch\
**Created:** [August 10, 2016, 11:03am UTC](https://discuss.elastic.co/t/nest-specify-type-name-on-mapping/57689 "2016-08-10T11:03:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Denis\_Lamanov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/denis_lamanov/32/13111_2.png) [@Denis\_Lamanov](https://discuss.elastic.co/u/Denis_Lamanov)\
**Post date:** [August 10, 2016, 11:03am UTC](https://discuss.elastic.co/t/nest-specify-type-name-on-mapping/57689/1 "2016-08-10T11:03:59Z")

</div>

Hi guys,

This code:

```
client.CreateIndex(indexName,
      s => s.Mappings(ms => ms
       .Map<NestedMessage>(m => m.AutoMap())));

```

will generate mapping for type with name "nestedMessage":

`{"mappings":{"nestedMessage":{"properties":{ .. }}}}`

Is there any way to rename it?

Thanks

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [August 11, 2016, 5:52am UTC](https://discuss.elastic.co/t/nest-specify-type-name-on-mapping/57689/2 "2016-08-11T05:52:03Z")

</div>

Yes, you can name the type in Elasticsearch differently to your POCO a few different ways

1.Using the `ElasticsearchType` attribute applied to `NestedMessage` and specifying the `Name` property

```
[ElasticsearchType(Name="message")]
public class NestedMessage
{
}

```

2.Using `InferMappingFor<T>()` on `ConnectionSettings`

```
var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
var settings = new ConnectionSettings(pool)
    .InferMappingFor<NestedMessage>(m => m
        .TypeName("message")
    );

var client = new ElasticClient(settings);

client.CreateIndex("index-name", s => s
    .Mappings(ms => ms
        .Map<NestedMessage>(m => m
            .AutoMap()
        )
    )
);

```

3.Using `.MapDefaultTypeNames()` on ConnectionSettings (although this will be removed in future, `InferMappingFor<T>()` is the way to go. Listed here for completeness)

```
var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
var settings = new ConnectionSettings(pool)
    .MapDefaultTypeNames(d => d
        .Add(typeof(NestedMessage), "message")
    );

var client = new ElasticClient(settings);

client.CreateIndex("index-name", s => s
    .Mappings(ms => ms
        .Map<NestedMessage>(m => m
            .AutoMap()
        )
    )
);

```

All will yield

```
{
  "mappings": {
    "message": {
      "properties": {}
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![Denis\_Lamanov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/denis_lamanov/32/13111_2.png) [@Denis\_Lamanov](https://discuss.elastic.co/u/Denis_Lamanov)\
**Post date:** [August 11, 2016, 12:39pm UTC](https://discuss.elastic.co/t/nest-specify-type-name-on-mapping/57689/3 "2016-08-11T12:39:54Z")

</div>

Hi,

Perfect, thanks

---

<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, 10:28pm UTC](https://discuss.elastic.co/t/nest-specify-type-name-on-mapping/57689/4 "2017-07-05T22:28:23Z")

</div>


