# Creation of an Index By Strongly Typed Classes

**URL:** <https://discuss.elastic.co/t/creation-of-an-index-by-strongly-typed-classes/102176>\
**Category:** Elasticsearch\
**Created:** [September 28, 2017, 7:49pm UTC](https://discuss.elastic.co/t/creation-of-an-index-by-strongly-typed-classes/102176 "2017-09-28T19:49:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarkG](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@MarkG](https://discuss.elastic.co/u/MarkG)\
**Post date:** [September 28, 2017, 7:49pm UTC](https://discuss.elastic.co/t/creation-of-an-index-by-strongly-typed-classes/102176/1 "2017-09-28T19:49:29Z")

</div>

I'm experimenting with creating an index but using the strongly typed classes.  
The basic desire is being able to specify an index WITHOUT using C# POCO document class. A tall order I realize since I can't use Mapping Attributes or Fluent Mapping or the POCO via the AutoMapper.

The problem that I'm running into is how to create a TypeMapping object successfully so that I can set it's properties and marry it to a TypeName object.

The code below does create an index (good thing) but I can't seem to figure out how to instantiate a TypeName object (bad thing). I know I'm being dense but I'm having a helluva time since the documentation doesn't actually address using these strongly typed classes at all (or I haven't found the doc pages yet).

Any help would be appreciated.

C# Code that I'm using:

var settings = new IndexSettings();  
settings.NumberOfReplicas = 0;  
settings.NumberOfShards = 2;

var indexConfig = new IndexState  
{  
Settings = settings  
};

var indexMappings = new Mappings();

var aType = new TypeName();  
[aType.Name](http://aType.Name) = "Index Column Name;  
aType.Type = typeof(string);

// A basic object but has nothing defined in it and I haven't found how to hydrate one up via a factory.  
var aTypeMapping = new TypeMapping();

indexMappings.Add(aType, aTypeMapping);

var indexCreateRequest = new CreateIndexRequest(CurrentIndexName, indexConfig);  
indexCreateRequest.Mappings = indexMappings;

var aResponse = Client.CreateIndex(indexCreateRequest);

And the index that's created:

{  
"dynamicindex-28-09-2017-19-26-14": {  
"aliases": {  
"dynamicindex": {}  
},  
"mappings": {  
"FirstName": {},  
"Email": {},  
"LastName": {},  
"Age": {}  
},  
"settings": {  
"index": {  
"creation\_date": "1506626774660",  
"number\_of\_shards": "2",  
"number\_of\_replicas": "0",  
"uuid": "rVNvrRcJQrmTxfV7JDczXA",  
"version": {  
"created": "5060199"  
},  
"provided\_name": "dynamicindex-28-09-2017-19-26-14"  
}  
}  
}  
}

---

<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:** [October 26, 2017, 7:50pm UTC](https://discuss.elastic.co/t/creation-of-an-index-by-strongly-typed-classes/102176/2 "2017-10-26T19:50:01Z")

</div>

Closed on October 26, 2017, 7:50pm UTC

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