# Is this the correct impl' for customizing \`\_id\` meta data field

**URL:** https://discuss.elastic.co/t/is-this-the-correct-impl-for-customizing-id-meta-data-field/349059
**Category:** Elasticsearch
**Tags:** docker, language-clients
**Created:** [December 11, 2023, 3:22pm UTC](https://discuss.elastic.co/t/is-this-the-correct-impl-for-customizing-id-meta-data-field/349059 "2023-12-11T15:22:19Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![iby\_dev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/iby_dev/32/127095_2.png) [@iby\_dev](https://discuss.elastic.co/u/iby_dev)
#### Post date: [December 11, 2023, 3:22pm UTC](https://discuss.elastic.co/t/is-this-the-correct-impl-for-customizing-id-meta-data-field/349059/1 "2023-12-11T15:22:19Z")

</div>

To get Elasticsearch docker image version:

```
image: docker.elastic.co/elasticsearch/elasticsearch:7.16.2

```

To accept a client side customized UUID on the `_id` field i had to change the: `dynamic: strict` property to `true`.

All this time, we have been using `strict` and auto generated `UUIDs` for the `_id` field.

When inspecting, the newly inserted document, i noticed a new field is added: `id` whose contents are matched exactly onto the `_id` metadata field.

Is this the expected behaviour, is this right way of achieving what i set out to do, which is to generate UUIDs, client side and then push to ELASTIC via bulk insert method.

I am using c# and the nest nuget package in dotnet 7.

Thanks for reading.

---

<div class="post-metadata">

### Author: ![iby\_dev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/iby_dev/32/127095_2.png) [@iby\_dev](https://discuss.elastic.co/u/iby_dev)
#### Post date: [December 12, 2023, 1:55pm UTC](https://discuss.elastic.co/t/is-this-the-correct-impl-for-customizing-id-meta-data-field/349059/2 "2023-12-12T13:55:14Z")

</div>

I changed my client side implementation to have a property named "\_Id".

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/a/2/a2bdf9533e0e5969293acfe0df64712514915f80.png)

In the error logs i see, it is indeed mapped correctly.

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

But i get bad request 400 errors on bulk insert.

When i try a single insert using the 1 json doc payload, i get a 201 created response.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/9/29363dd959fd76cf9ee25b419c3c213a0b227c64.png)

Elastic ignores the client side generated UUId.

---

<div class="post-metadata">

### Author: ![iby\_dev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/iby_dev/32/127095_2.png) [@iby\_dev](https://discuss.elastic.co/u/iby_dev)
#### Post date: [December 12, 2023, 3:52pm UTC](https://discuss.elastic.co/t/is-this-the-correct-impl-for-customizing-id-meta-data-field/349059/3 "2023-12-12T15:52:09Z")

</div>

When going back to the dynamic mode: "strict", there is no winning with Elastic Search API. I get confusing and conflicting error messages:

`"Field [_id] is a metadata field and cannot be added inside a document. Use the index API request parameters.""`  
Or  
` "type" : "strict_dynamic_mapping_exception", "reason" : "mapping set to strict, dynamic introduction of [id] within [_doc] is not allowed",`

I do not want to add a new field/property to the document, i just want to customize the metadata field called: `_id`.

Why is this so hard?

---

<div class="post-metadata">

### Author: ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)
#### Post date: [December 12, 2023, 4:10pm UTC](https://discuss.elastic.co/t/is-this-the-correct-impl-for-customizing-id-meta-data-field/349059/4 "2023-12-12T16:10:50Z")

</div>

I am confused ... this is not an Elasticsearch REST API Endpoint.

 ![Screenshot 2023-12-12 at 8.07.49 AM](https://us1.discourse-cdn.com/elastic/original/3X/6/a/6a90561f9aa8a7cbecb080ba7f4c221567183b80.png)

So, it is unclear how you are accessing Elasticsearch. Do you have a proxy or app in between?

> **[Index API | Elasticsearch Guide \[8.11\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html)**

> **[Bulk API | Elasticsearch Guide \[8.11\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html)**

---

<div class="post-metadata">

### Author: ![iby\_dev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/iby_dev/32/127095_2.png) [@iby\_dev](https://discuss.elastic.co/u/iby_dev)
#### Post date: [December 12, 2023, 4:15pm UTC](https://discuss.elastic.co/t/is-this-the-correct-impl-for-customizing-id-meta-data-field/349059/5 "2023-12-12T16:15:19Z")

</div>

Hi Stephen, i am using the nest chsarp library like so:

single doc:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/4/c/4c451f01dd9fc1ffbf73c8f9f26361f714c68442.png)

many docs:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/e/2/e2e67296f78360c429c26da7b1d1561a0af529e4.png)

The NEST sdk confers the c# logic above to a low level client which in the end talks to the ES API. Does this clarify my usage?

---

<div class="post-metadata">

### Author: ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)
#### Post date: [December 12, 2023, 4:17pm UTC](https://discuss.elastic.co/t/is-this-the-correct-impl-for-customizing-id-meta-data-field/349059/6 "2023-12-12T16:17:12Z")

</div>

The `_id` is the "resource" id and goes on the end of the URL

```auto
POST my_index/_doc/12345678-999
{
  "foo" : "bar"
}

GET my_index/_search

# POST my_index/_doc/12345678-999 201 Created
{
  "_index": "my_index",
  "_id": "12345678-999",
  "_version": 1,
  "result": "created",
  "_shards": {
    "total": 2,
    "successful": 1,
    "failed": 0
  },
  "_seq_no": 0,
  "_primary_term": 1
}
# GET my_index/_search 200 OK
{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 1,
      "relation": "eq"
    },
    "max_score": 1,
    "hits": [
      {
        "_index": "my_index",
        "_id": "12345678-999",
        "_score": 1,
        "_source": {
          "foo": "bar"
        }
      }
    ]
  }
}

```

---

<div class="post-metadata">

### Author: ![iby\_dev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/iby_dev/32/127095_2.png) [@iby\_dev](https://discuss.elastic.co/u/iby_dev)
#### Post date: [December 12, 2023, 4:19pm UTC](https://discuss.elastic.co/t/is-this-the-correct-impl-for-customizing-id-meta-data-field/349059/7 "2023-12-12T16:19:30Z")

</div>

Shouldn't the nest c# library do this for me? What purpose do this extension method solve then?

` .Id(document._id)`

or do i have to manually construct the http api call myself ?

---

<div class="post-metadata">

### Author: ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)
#### Post date: [December 12, 2023, 4:19pm UTC](https://discuss.elastic.co/t/is-this-the-correct-impl-for-customizing-id-meta-data-field/349059/8 "2023-12-12T16:19:40Z")

</div>

Please do not past screen shots of text... really hard to work with

---

<div class="post-metadata">

### Author: ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)
#### Post date: [December 12, 2023, 4:20pm UTC](https://discuss.elastic.co/t/is-this-the-correct-impl-for-customizing-id-meta-data-field/349059/9 "2023-12-12T16:20:47Z")

</div>

I am not the C# expert.... I will have to take a look but I think it is important that you understand the underlying calls... you do not set `_id` as a normal property that is the error message you are getting.

---

<div class="post-metadata">

### Author: ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)
#### Post date: [December 12, 2023, 4:21pm UTC](https://discuss.elastic.co/t/is-this-the-correct-impl-for-customizing-id-meta-data-field/349059/10 "2023-12-12T16:21:18Z")

</div>

with the `_bulk` endpoint you can do that as part of the payload.

---

<div class="post-metadata">

### Author: ![iby\_dev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/iby_dev/32/127095_2.png) [@iby\_dev](https://discuss.elastic.co/u/iby_dev)
#### Post date: [December 12, 2023, 4:23pm UTC](https://discuss.elastic.co/t/is-this-the-correct-impl-for-customizing-id-meta-data-field/349059/11 "2023-12-12T16:23:16Z")

</div>

It would be cool if you could refer my Q to a c# expert at ES. That would be greatly appreciated.

I have tried the `_bulk` endpoint and the i can see the mapped `_id` properties when the error messages are logged and handled. But every document gets rejected. Let me try again.

---

<div class="post-metadata">

### Author: ![iby\_dev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/iby_dev/32/127095_2.png) [@iby\_dev](https://discuss.elastic.co/u/iby_dev)
#### Post date: [December 12, 2023, 4:27pm UTC](https://discuss.elastic.co/t/is-this-the-correct-impl-for-customizing-id-meta-data-field/349059/12 "2023-12-12T16:27:34Z")

</div>

@stephenb - will this work if the mapping schema document is set to: dynamic: strict ?

---

<div class="post-metadata">

### Author: ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)
#### Post date: [December 12, 2023, 4:29pm UTC](https://discuss.elastic.co/t/is-this-the-correct-impl-for-customizing-id-meta-data-field/349059/13 "2023-12-12T16:29:23Z")

</div>

I pinged internally...

I do not think `dynamic: strict ` is a factor

---

<div class="post-metadata">

### Author: ![iby\_dev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/iby_dev/32/127095_2.png) [@iby\_dev](https://discuss.elastic.co/u/iby_dev)
#### Post date: [December 12, 2023, 4:30pm UTC](https://discuss.elastic.co/t/is-this-the-correct-impl-for-customizing-id-meta-data-field/349059/14 "2023-12-12T16:30:21Z")

</div>

Ok thanks for claryfing, my tech lead advises we dont want to change to:  
`dynamic: true`.

---

<div class="post-metadata">

### Author: ![iby\_dev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/iby_dev/32/127095_2.png) [@iby\_dev](https://discuss.elastic.co/u/iby_dev)
#### Post date: [December 12, 2023, 4:52pm UTC](https://discuss.elastic.co/t/is-this-the-correct-impl-for-customizing-id-meta-data-field/349059/15 "2023-12-12T16:52:29Z")

</div>

I tried the `.BulkAll()` method with a list of documents passed to it. Each document has a pregenerated `UUID` assigned to a `_id` property on each document.

The `DroppedDocumentCallback()` callback function is triggered revealing no errors why the document was dropped. Looking closely at the logs, i see:

```auto
2023-12-12 16:32:26 2023-12-12 16:32:26.332 +00:00 [My Worker] [my_scan_1] [] [ERR] [1deab1ef21cc] [Development] [1.0.0.0] Dropped doc - on index: cds_scan_1-doc with _id: hWLfXowBADcS-dXjXrm2
2023-12-12 16:32:26 Api Response: Status: 400 Result: 
2023-12-12 16:32:26 Error Response: {"headers":{},"root_cause":null}
2023-12-12 16:32:26 Failed doc: {"_id":"Ba/FyFrAslLo9b82OurV","file_type":"csv","file_name":"20121001 Setembro.csv","ingest":"2023-12-12T16:32:26.0732641+00:00" .... }.

```

> You can see two different ids have been generated, one by me client side (_Ba/FyFrAslLo9b82OurV_) and another (_hWLfXowBADcS-dXjXrm2_) by, ES API - this is revealed by inspecting the: `BulkResponseItemBase.Id` property.

---

<div class="post-metadata">

### Author: ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)
#### Post date: [December 12, 2023, 4:55pm UTC](https://discuss.elastic.co/t/is-this-the-correct-impl-for-customizing-id-meta-data-field/349059/16 "2023-12-12T16:55:32Z")

</div>

The .NET lead is out today, hopefully he can take a look tomorrow..

---

<div class="post-metadata">

### Author: ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)
#### Post date: [December 12, 2023, 4:57pm UTC](https://discuss.elastic.co/t/is-this-the-correct-impl-for-customizing-id-meta-data-field/349059/17 "2023-12-12T16:57:36Z")

</div>

Sorry, I'm not really following all the "snippets."

Documents can be dropped for several reasons...

For tomorrow I would think you would want to show a sample of the CSV, your template, and your C# code...

---

<div class="post-metadata">

### Author: ![iby\_dev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/iby_dev/32/127095_2.png) [@iby\_dev](https://discuss.elastic.co/u/iby_dev)
#### Post date: [December 13, 2023, 10:48am UTC](https://discuss.elastic.co/t/is-this-the-correct-impl-for-customizing-id-meta-data-field/349059/18 "2023-12-13T10:48:33Z")

</div>

I got this working, now, i will post an update shortly.

---

<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: [January 10, 2024, 10:49am UTC](https://discuss.elastic.co/t/is-this-the-correct-impl-for-customizing-id-meta-data-field/349059/19 "2024-01-10T10:49:09Z")

</div>

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