# Create index pattern from C# Nest

**URL:** <https://discuss.elastic.co/t/create-index-pattern-from-c-nest/249113>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [September 18, 2020, 2:06pm UTC](https://discuss.elastic.co/t/create-index-pattern-from-c-nest/249113 "2020-09-18T14:06:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alder](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alder/32/58170_2.png) [@Alder](https://discuss.elastic.co/u/Alder)\
**Post date:** [September 18, 2020, 2:06pm UTC](https://discuss.elastic.co/t/create-index-pattern-from-c-nest/249113/1 "2020-09-18T14:06:24Z")

</div>

Hello everyone.  
I need to create an index pattern using C # Nest, without using kibana.  
I searched the Nest API but didn't find it. Is possible create index pattern using the Nest API?

Regards,

Alder

---

<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:** [September 24, 2020, 1:20am UTC](https://discuss.elastic.co/t/create-index-pattern-from-c-nest/249113/2 "2020-09-24T01:20:13Z")

</div>

Yes, it's possible to create an index template with an index pattern with Nest (high level client) or [Elasticsearch.Net](http://Elasticsearch.Net) (low level client)

Assuming 7.x versions, with Nest

```auto
var client = new ElasticClient();

var response = client.Indices.PutTemplate("template_name", p => p
	.IndexPatterns("foo-*")
	.Map(m => m
		.DynamicTemplates(d => d
			.DynamicTemplate("strings", dt => dt
				.MatchMappingType("string")
				.Mapping(mm => mm
					.Text(t => t
						.Fields(f => f
							.Keyword(k => k
								.Name("raw")
								.IgnoreAbove(256)
							)
						)
					)
				)
			)
		)
	)
);

```

or using the object initializer syntax to construct a request

```auto
var request = new PutIndexTemplateRequest("template_name")
{
	IndexPatterns = new[] { "foo" },
	Mappings = new TypeMapping
	{
		DynamicTemplates = new DynamicTemplateContainer
		{
			{ "strings", new DynamicTemplate
				{
					MatchMappingType = "string",
					Mapping = new TextProperty
					{
						Fields = new Properties
						{
							{ "raw", new KeywordProperty
								{
									Name = "raw",
									IgnoreAbove = 256
								}
							}
						}
					}

				}
			}
		}
	}
};

var response = client.Indices.PutTemplate(request);

```

both yield the request

```json
PUT <scheme://host:port>/_template/template_name
{
  "index_patterns": [
    "foo-*"
  ],
  "mappings": {
    "dynamic_templates": [
      {
        "strings": {
          "mapping": {
            "fields": {
              "raw": {
                "ignore_above": 256,
                "type": "keyword"
              }
            },
            "type": "text"
          },
          "match_mapping_type": "string"
        }
      }
    ]
  }
}

```

With the low level client

```auto
var lowLevelClient = new ElasticLowLevelClient();

var json = @"{
  ""index_patterns"": [
    ""foo-*""
  ],
  ""mappings"": {
    ""dynamic_templates"": [
      {
        ""strings"": {
          ""mapping"": {
            ""fields"": {
              ""raw"": {
                ""ignore_above"": 256,
                ""type"": ""keyword""
              }
            },
            ""type"": ""text""
          },
          ""match_mapping_type"": ""string""
        }
      }
    ]
  }
}";

var stringResponse = lowLevelClient.Indices.PutTemplateForAll<StringResponse>(
    "template_name", 
    PostData.String(json));

```

---

<div class="post-metadata">

**Author:** ![Alder](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alder/32/58170_2.png) [@Alder](https://discuss.elastic.co/u/Alder)\
**Post date:** [October 6, 2020, 1:09pm UTC](https://discuss.elastic.co/t/create-index-pattern-from-c-nest/249113/3 "2020-10-06T13:09:22Z")

</div>

Thank you very much

---

<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:** [November 3, 2020, 1:09pm UTC](https://discuss.elastic.co/t/create-index-pattern-from-c-nest/249113/4 "2020-11-03T13:09:24Z")

</div>

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