# GetIndexTemplate() call throws an exception

**URL:** <https://discuss.elastic.co/t/getindextemplate-call-throws-an-exception/339329>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [July 26, 2023, 4:09pm UTC](https://discuss.elastic.co/t/getindextemplate-call-throws-an-exception/339329 "2023-07-26T16:09:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ksobon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ksobon/32/103774_2.png) [@ksobon](https://discuss.elastic.co/u/ksobon)\
**Post date:** [July 26, 2023, 4:09pm UTC](https://discuss.elastic.co/t/getindextemplate-call-throws-an-exception/339329/1 "2023-07-26T16:09:41Z")

</div>

I am trying to get an index template using the .NET APIs via Elastic.Clients.Elasticsearch and Elastic.Transport libraries.

I got my client setup like this:

```auto
var credentials = new BasicAuthentication(elasticUsername, elasticPassword);
var connPool = new CloudNodePool(cloudId, credentials);
var client = new ElasticsearchClient(new ElasticsearchClientSettings(connPool));

```

Then I would call this:

```auto
var indexTemplateRequest = new GetIndexTemplateRequest("template_1");
var response = client.Indices.GetIndexTemplate(indexTemplateRequest);

```

That results in an exception:

```auto
The JSON value could not be converted to System.Nullable`1[Elastic.Clients.Elasticsearch.Mapping.DynamicMapping]. Path: $.index_templates[0].index_template.template.mappings.dynamic | LineNumber: 0 | BytePositionInLine: 496.

```

Any ideas what's going on here?

---

<div class="post-metadata">

**Author:** ![Opster\_support](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/opster_support/32/56687_2.png) [@Opster\_support](https://discuss.elastic.co/u/Opster_support)\
**Post date:** [July 26, 2023, 6:11pm UTC](https://discuss.elastic.co/t/getindextemplate-call-throws-an-exception/339329/2 "2023-07-26T18:11:31Z")

</div>

I used [opsgpt.io](http://opsgpt.io) as i am was entirely sure of the answer...

The error message you're seeing suggests that there's a problem with the JSON serialization/deserialization process. The .NET client is trying to convert a JSON value to a nullable `DynamicMapping` type, but it's failing to do so. This could be due to a mismatch between the data in your Elasticsearch index template and the .NET types that the client library is using to represent that data.

Here are a few things you could try:

1. Check the version compatibility: Ensure that the version of Elasticsearch you're using is compatible with the version of the .NET client library. There might be breaking changes in the mapping definitions between different versions of Elasticsearch.

2. Inspect the index template: You can manually inspect the index template by running a GET request to `/_template/template_1` in Kibana Dev Tools or via curl. Check the `mappings` section of the template, especially the `dynamic` field. The value of the `dynamic` field should be a boolean or a string ("true", "false", "strict").

3. Update the client library: If you're not using the latest version of the .NET client library, consider updating it. There might be bug fixes or improvements related to JSON serialization/deserialization.

4. Custom JSON converter: If the issue persists, you might need to implement a custom JSON converter for the `DynamicMapping` type. This would allow you to control how the `DynamicMapping` type is serialized and deserialized.

If none of these suggestions work, it would be helpful to see the actual index template (the JSON returned by the GET request to `/_template/template_1`). This could provide more clues about what's causing the issue.

---

<div class="post-metadata">

**Author:** ![ksobon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ksobon/32/103774_2.png) [@ksobon](https://discuss.elastic.co/u/ksobon)\
**Post date:** [July 26, 2023, 6:25pm UTC](https://discuss.elastic.co/t/getindextemplate-call-throws-an-exception/339329/3 "2023-07-26T18:25:47Z")

</div>

@Opster_support could it be that some of the "dynamic" fields for index templates have a value set to `"true"` and some to `true` (notice no quotations marks) meaning that some of them are stored as `Booleans` and some as `strings`?

The specific index template that I am trying to retrieve has it stored as a Boolean `true`:

```auto
{
  "index_templates": [
    {
      "name": "debug-1.0.0",
      "index_template": {
        "index_patterns": [
          "beat-debug-1.0.0*"
        ],
        "template": {
          "settings": {
            "index": {
              "lifecycle": {
                "name": "debugbeat",
                "rollover_alias": "beat-debug-1.0.0"
              },
              "number_of_shards": "1",
              "priority": "100",
              "number_of_replicas": "1"
            }
          },
          "mappings": {
            "_routing": {
              "required": false
            },
            "numeric_detection": false,
            "dynamic_date_formats": [
              "strict_date_optional_time",
              "yyyy/MM/dd HH:mm:ss Z||yyyy/MM/dd Z"
            ],
            "_source": {
              "excludes": [],
              "includes": [],
              "enabled": true
            },
            "dynamic": true,
            "dynamic_templates": [],
            "date_detection": true,
            "properties": {
              "computer": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "keyword"
                  }
                }
              },
              "@timestamp": {
                "type": "date"
              },
              "file": {
                "type": "object",
                "properties": {
                  "path": {
                    "type": "keyword"
                  },
                  "name": {
                    "type": "keyword"
                  },
                  "size(mb)": {
                    "coerce": true,
                    "ignore_malformed": true,
                    "type": "double"
                  }
                }
              },
              "software": {
                "type": "object",
                "properties": {
                  "version": {
                    "type": "keyword"
                  }
                }
              },
              "action": {
                "type": "object",
                "properties": {
                  "duration": {
                    "coerce": true,
                    "ignore_malformed": true,
                    "type": "double"
                  },
                  "name": {
                    "type": "keyword"
                  }
                }
              },
              "message": {
                "type": "text"
              },
              "user": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "keyword"
                  }
                }
              }
            }
          }
        },
        "composed_of": [
          "logs-mappings"
        ],
        "version": 1
      }
    }
  ]
}

```

Is there a way to handle both cases ie. coerce the value from boolean `true` to string `"true"` or vice versa?

---

<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 23, 2023, 6:26pm UTC](https://discuss.elastic.co/t/getindextemplate-call-throws-an-exception/339329/4 "2023-08-23T18:26:40Z")

</div>

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