# Docs for indexing a document leads to an error \[Elasticsearch.NET 8.13.12\]

**URL:** https://discuss.elastic.co/t/docs-for-indexing-a-document-leads-to-an-error-elasticsearch-net-8-13-12/359842
**Category:** Elasticsearch
**Tags:** language-clients
**Created:** [May 20, 2024, 2:37pm UTC](https://discuss.elastic.co/t/docs-for-indexing-a-document-leads-to-an-error-elasticsearch-net-8-13-12/359842 "2024-05-20T14:37:08Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Motsols](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/motsols/32/134658_2.png) [@Motsols](https://discuss.elastic.co/u/Motsols)
#### Post date: [May 20, 2024, 2:37pm UTC](https://discuss.elastic.co/t/docs-for-indexing-a-document-leads-to-an-error-elasticsearch-net-8-13-12/359842/1 "2024-05-20T14:37:08Z")

</div>

I'm using the latest .NET client for elasticsearch.

The docs shows this as an example of how to index documents: [Getting started | Elasticsearch .NET Client [8.9] | Elastic](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/getting-started-net.html#_indexing_documents)

When writing the same code in VS Community 2022 17.9.7 as well as VS Code it shows an error that the call is ambiguous:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/1/d/1d2fc999e2009d871157edcbebba71d250d1b166.png)

Pasting the error here as well for searchability.  
error CS0121: The call is ambiguous between the following methods or properties: 'ElasticsearchClient.IndexAsync(TDocument, IndexName, CancellationToken)' and 'ElasticsearchClient.IndexAsync(TDocument, Id?, CancellationToken)'

* * *

Is casting the string the correct way to index documents now? If so I'd love to see the documentation updated to reflect the recent changes to the .NET client.

```auto
var response = await _esClient.IndexAsync(doc, (IndexName)"my_index");

```

Edit:  
My post was flagged as spam for being overly promotional. What is promotional? I don't see why this would be flagged, as it may help future people with the same question find the answer without posting their own question.

---

<div class="post-metadata">

### Author: ![flobernd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flobernd/32/124877_2.png) [@flobernd](https://discuss.elastic.co/u/flobernd)
#### Post date: [May 20, 2024, 6:20pm UTC](https://discuss.elastic.co/t/docs-for-indexing-a-document-leads-to-an-error-elasticsearch-net-8-13-12/359842/2 "2024-05-20T18:20:32Z")

</div>

Hi @Motsols,

casting to IndexName is one option. The other one would be to use a named argument like:

client.IndexAsync(doc, index: „my\_index“)

I think the ambiguity comes from the fact that both, IndexName and Id, have implicit conversion operators from string.

Still looking for a better solution here, but if there is no good way to improve this situation, I’ll make sure to update the docs.

---

<div class="post-metadata">

### Author: ![Motsols](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/motsols/32/134658_2.png) [@Motsols](https://discuss.elastic.co/u/Motsols)
#### Post date: [May 23, 2024, 3:45pm UTC](https://discuss.elastic.co/t/docs-for-indexing-a-document-leads-to-an-error-elasticsearch-net-8-13-12/359842/3 "2024-05-23T15:45:05Z")

</div>

I think it's still good to keep the docs updated while you investigate as it is one bump on the road to a smooth implementation of Elasticsearch.

---

<div class="post-metadata">

### Author: ![flobernd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flobernd/32/124877_2.png) [@flobernd](https://discuss.elastic.co/u/flobernd)
#### Post date: [May 6, 2025, 12:28pm UTC](https://discuss.elastic.co/t/docs-for-indexing-a-document-leads-to-an-error-elasticsearch-net-8-13-12/359842/4 "2025-05-06T12:28:49Z")

</div>

FYI: This ambigous syntax is gone in 9.0.0 ([read more about this here](https://www.elastic.co/docs/release-notes/elasticsearch/clients/dotnet/breaking-changes#3-removal-of-certain-descriptor-constructors-and-related-request-apis)) and this change will be backported to the 8.x branch for 8.19.0.
