# I can't understand something in the opensearch-go example, is it a mistake?

**URL:** <https://forum.opensearch.org/t/i-cant-understand-something-in-the-opensearch-go-example-is-it-a-mistake/9074>\
**Category:** OpenSearch Client Libraries\
**Tags:** opensearch-go\
**Created:** [March 29, 2022, 12:24pm UTC](https://forum.opensearch.org/t/i-cant-understand-something-in-the-opensearch-go-example-is-it-a-mistake/9074 "2022-03-29T12:24:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nethlaria](https://avatars.discourse-cdn.com/v4/letter/n/cab0a1/32.png) [@nethlaria](https://forum.opensearch.org/u/nethlaria)\
**Post date:** [March 29, 2022, 12:24pm UTC](https://forum.opensearch.org/t/i-cant-understand-something-in-the-opensearch-go-example-is-it-a-mistake/9074/1 "2022-03-29T12:24:46Z")

</div>

Looking at this:

> <https://github.com/opensearch-project/opensearch-go/blob/main/USER_GUIDE.md#example>

When it defines the mapping, it uses opensearchapi.CreateRequest() but as far as I can see that doesn’t send anything and would need a Do() call. So is that a no-op or does it have some effect I’m not aware of?

I tried adding a Do() but Opensearch complains about the Document ID being missing like this:

[400 Bad Request] {“error”:{“root\_cause”:[{“type”:“illegal\_argument\_exception”,“reason”:“if \_id is specified it must not be empty”}],“type”:“illegal\_argument\_exception”,“reason”:“if \_id is specified it must not be empty”},“status”:400}

So then how am I supposed to create a mapping and should the example be updated?  
Thanks for reading.

---

<div class="post-metadata">

**Author:** ![Vijay](https://avatars.discourse-cdn.com/v4/letter/v/4bbf92/32.png) [@Vijay](https://forum.opensearch.org/u/Vijay)\
**Post date:** [March 29, 2022, 5:41pm UTC](https://forum.opensearch.org/t/i-cant-understand-something-in-the-opensearch-go-example-is-it-a-mistake/9074/2 "2022-03-29T17:41:09Z")

</div>

@nethlaria CreateRequest is not a method, instead, it only initialize parameters for the request. The method ‘Do’ will perform action based on CreateRequest parameters. Can you post your complete code so that i can understand why your request fails? Thanks

---

<div class="post-metadata">

**Author:** ![nethlaria](https://avatars.discourse-cdn.com/v4/letter/n/cab0a1/32.png) [@nethlaria](https://forum.opensearch.org/u/nethlaria)\
**Post date:** [March 29, 2022, 6:30pm UTC](https://forum.opensearch.org/t/i-cant-understand-something-in-the-opensearch-go-example-is-it-a-mistake/9074/3 "2022-03-29T18:30:45Z")

</div>

@Vijay Thanks for responding. I was really asking about the example code in the User Guide. Let me put it another way: If that CreateRequest does not send anything, what is the mapping string for?

---

<div class="post-metadata">

**Author:** ![Vijay](https://avatars.discourse-cdn.com/v4/letter/v/4bbf92/32.png) [@Vijay](https://forum.opensearch.org/u/Vijay)\
**Post date:** [March 31, 2022, 1:05am UTC](https://forum.opensearch.org/t/i-cant-understand-something-in-the-opensearch-go-example-is-it-a-mistake/9074/4 "2022-03-31T01:05:51Z")

</div>

@nethlaria I understood your question now. You are right. The example is incomplete. I created a [bug](https://github.com/opensearch-project/opensearch-go/issues/98) to update the same. Thanks for bringing this up.

---

<div class="post-metadata">

**Author:** ![Vijay](https://avatars.discourse-cdn.com/v4/letter/v/4bbf92/32.png) [@Vijay](https://forum.opensearch.org/u/Vijay)\
**Post date:** [March 31, 2022, 1:28am UTC](https://forum.opensearch.org/t/i-cant-understand-something-in-the-opensearch-go-example-is-it-a-mistake/9074/5 "2022-03-31T01:28:29Z")

</div>

In the meantime, i will do something like below to create index

```auto
	mapping := map[string]interface{}{
		"settings": map[string]interface{}{
			"index": map[string]interface{}{
				"number_of_shards": 4,
				},
			},
	}
	jsonBody, _ := json.Marshal(mapping)
	// Create an index with non-default settings.
	indexCreateRequest := opensearchapi.IndicesCreateRequest{
		Index: IndexName,
		Body: bytes.NewReader(jsonBody),
	}

	indexResponse, err := indexCreateRequest.Do(context.Background(), client)
	if err != nil {
		fmt.Println("failed to create index ", err)
		os.Exit(1)
	}
	fmt.Println(indexResponse)

```
