# NEST don't apply attribute mapping

**URL:** <https://discuss.elastic.co/t/nest-dont-apply-attribute-mapping/190934>\
**Category:** Elasticsearch\
**Created:** [July 17, 2019, 9:16am UTC](https://discuss.elastic.co/t/nest-dont-apply-attribute-mapping/190934 "2019-07-17T09:16:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dsonjohn404](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dsonjohn404/32/50104_2.png) [@dsonjohn404](https://discuss.elastic.co/u/dsonjohn404)\
**Post date:** [July 17, 2019, 9:16am UTC](https://discuss.elastic.co/t/nest-dont-apply-attribute-mapping/190934/1 "2019-07-17T09:16:17Z")

</div>

Hi,  
I use nest 7.0.0 and [asp.net](http://asp.net) core 2.2. i want to create indxe from poco class. in elasticsearch index create but without any mapping. create index method is :

```auto
public async Task CreateIndex()
{
	try
	{
		var getIndexResponse =await ElasticClient.Indices.GetAsync("myindex");
		if (getIndexResponse.Indices == null || !getIndexResponse.Indices.Any())
		{
			var createIndexResponse = await ElasticClient.Indices.CreateAsync("myindex", c => c
				.Map(p => p.AutoMap<MyModel>()));
		}
	}
	catch (Exception)
	{
	}
}

```

and MyModel is like this:

```auto
[ElasticsearchType(IdProperty = nameof(Id), RelationName = "MyModelMessage")]
public class MyModel
{
	[Number(NumberType.Long, Index = true, DocValues = false)]
	public long UserId { get; set; }
	[Date(Index = true)]
	public DateTime CreatedAt { get; set; }
	[Text(Index = false)]
	public string ObjectName { get; set; }
	[Date(Index = true)]
	public DateTime UpdateAt { get; set; }
}

```

---

<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 17, 2019, 10:51am UTC](https://discuss.elastic.co/t/nest-dont-apply-attribute-mapping/190934/2 "2019-07-17T10:51:30Z")

</div>

I checked this with NEST 7.0.1 against Elasticsearch 7.2.0 and I couldn't replicate the issue.

There's a few things that I would consider changing

1. Change

```auto
var getIndexResponse =await ElasticClient.Indices.GetAsync("myindex");
if (getIndexResponse.Indices == null || !getIndexResponse.Indices.Any())
{
	var createIndexResponse = await ElasticClient.Indices.CreateAsync("myindex", c => c
		.Map(p => p.AutoMap<MyModel>()));
}

```

to use the Index exists API

```auto
var indexExistsResponse = await ElasticClient.Indices.ExistsAsync("myindex");
if (!indexExistsResponse.Exists)
{
	var createIndexResponse = await ElasticClient.Indices.CreateAsync("myindex", c => c
		.Map(p => p.AutoMap<MyModel>()));
}

```

It makes a HTTP HEAD request, so don't need to deserialize and check a response body

1. Unless `ThrowExceptions()` is configured on `ConnectionSettings`, you likely don't need the `try/catch` block in this instance. Instead, you can check `.IsValid` on a response to determine if there was an issue with a request/response.

---

<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:** [August 14, 2019, 10:51am UTC](https://discuss.elastic.co/t/nest-dont-apply-attribute-mapping/190934/3 "2019-08-14T10:51:31Z")

</div>

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