# NEST library. Mapping

**URL:** https://discuss.elastic.co/t/nest-library-mapping/91329
**Category:** Elasticsearch
**Created:** [June 29, 2017, 5:55pm UTC](https://discuss.elastic.co/t/nest-library-mapping/91329 "2017-06-29T17:55:01Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![lcokru](https://avatars.discourse-cdn.com/v4/letter/l/bbce88/32.png) [@lcokru](https://discuss.elastic.co/u/lcokru)
#### Post date: [June 29, 2017, 5:55pm UTC](https://discuss.elastic.co/t/nest-library-mapping/91329/1 "2017-06-29T17:55:01Z")

</div>

I use NEST functionality to build mapping for my index. I do it in the following way:

```
		TypeMappingDescriptor<object> typeMappingDescriptor= new TypeMappingDescriptor<object>();

		typeMappingDescriptor.Map<object>(ms => ms
			.Properties(ps => ps
				.Text(txt => txt .Name("text").IncludeInAll())
				.Number(n=> n.Name("number").Type(NumberType.Byte).IncludeInAll())
			)
			.DynamicTemplates(x => x
				.DynamicTemplate("customanalyzer_for_strings", y => y
					.PathMatch("path")
					.MatchMappingType("string")
					.Mapping(t => t
						.Text(r => r
							.Fields(fg => fg
								.Keyword(k=> k.Name("raw"))))))));

```

And I want convert typeMappingDescriptor to string representation or Json like this:

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

```

How can I do it?

---

<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: [June 30, 2017, 4:39am UTC](https://discuss.elastic.co/t/nest-library-mapping/91329/2 "2017-06-30T04:39:24Z")

</div>

You can use the serializer used by the client

```
var client = new ElasticClient();
var jsonString = client.Serializer.SerializeToString(typeMappingDescriptor);
```

---

<div class="post-metadata">

### Author: ![lcokru](https://avatars.discourse-cdn.com/v4/letter/l/bbce88/32.png) [@lcokru](https://discuss.elastic.co/u/lcokru)
#### Post date: [June 30, 2017, 10:15am UTC](https://discuss.elastic.co/t/nest-library-mapping/91329/4 "2017-06-30T10:15:27Z")

</div>

Thank you for your help  
But can I use **Serializer.SerializeToString** without creating ElasticClient?

---

<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: [July 1, 2017, 12:50am UTC](https://discuss.elastic.co/t/nest-library-mapping/91329/5 "2017-07-01T00:50:09Z")

</div>

> [@lcokru](#):
>
> But can I use Serializer.SerializeToString without creating ElasticClient?

You can use

```
var serializer = new JsonNetSerializer(new ConnectionSettings(new Uri("http://localhost:9200")));
serializer.SerializeToString(typeMappingDescriptor);

```

but this is not really much different from just using an instance of the client. I'd recommend also using a singleton instance of the client if you need to serialize multiple objects as many caches are used internally.

---

<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 29, 2017, 12:50am UTC](https://discuss.elastic.co/t/nest-library-mapping/91329/6 "2017-07-29T00:50:12Z")

</div>

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