# How to create an index in ES6 that automatically assigns a Field value (Ex:- employee\_Id) found inside a document to \_id (Document ID) each time a new document is inserted

**URL:** <https://discuss.elastic.co/t/how-to-create-an-index-in-es6-that-automatically-assigns-a-field-value-ex-employee-id-found-inside-a-document-to-id-document-id-each-time-a-new-document-is-inserted/176425>\
**Category:** Elasticsearch\
**Created:** [April 11, 2019, 2:38pm UTC](https://discuss.elastic.co/t/how-to-create-an-index-in-es6-that-automatically-assigns-a-field-value-ex-employee-id-found-inside-a-document-to-id-document-id-each-time-a-new-document-is-inserted/176425 "2019-04-11T14:38:54Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nandan\_Reddy\_V](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nandan_reddy_v/32/43948_2.png) [@Nandan\_Reddy\_V](https://discuss.elastic.co/u/Nandan_Reddy_V)\
**Post date:** [April 11, 2019, 2:38pm UTC](https://discuss.elastic.co/t/how-to-create-an-index-in-es6-that-automatically-assigns-a-field-value-ex-employee-id-found-inside-a-document-to-id-document-id-each-time-a-new-document-is-inserted/176425/1 "2019-04-11T14:38:54Z")

</div>

How to create an index in ES6 that automatically assigns a Field value (Ex:- employee\_Id) found inside a document to \_id (Document ID) each time a new document is inserted

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 11, 2019, 3:30pm UTC](https://discuss.elastic.co/t/how-to-create-an-index-in-es6-that-automatically-assigns-a-field-value-ex-employee-id-found-inside-a-document-to-id-document-id-each-time-a-new-document-is-inserted/176425/2 "2019-04-11T15:30:53Z")

</div>

You can create an ingest pipeline that you can call when you index a document. It can set the `_id` from another field. See: [https://www.elastic.co/guide/en/elasticsearch/reference/7.0/script-processor.html](https://www.elastic.co/guide/en/elasticsearch/reference/7.0/script-processor.html)

---

<div class="post-metadata">

**Author:** ![Nandan\_Reddy\_V](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nandan_reddy_v/32/43948_2.png) [@Nandan\_Reddy\_V](https://discuss.elastic.co/u/Nandan_Reddy_V)\
**Post date:** [April 11, 2019, 5:27pm UTC](https://discuss.elastic.co/t/how-to-create-an-index-in-es6-that-automatically-assigns-a-field-value-ex-employee-id-found-inside-a-document-to-id-document-id-each-time-a-new-document-is-inserted/176425/3 "2019-04-11T17:27:35Z")

</div>

Thanks for sharing the above link, that helped me understand.

Although I was left with one more question based on the below scenario what I have:

- I am trying to push JSON document to Elastic using Fluentd.
- Fluentd connects to Elastic and Push document to a index
- As per the requirement we need to do a POST call with Unique ID [employee\_Id] each time to insert new document or re-insert the whole document with new data (If document ID already exist).  
Ex:- Below 12345 - is the employee\_Id  
post Employeedata/Employees/12345  
{  
"employee\_id": "12345",  
"title": "Programmer",  
"Desc": "Java Dev",  
"Sal":"9100.00"  
}
- So if Elastic receives the data from Fluentd to write to a index, is there any way to make Elastic index intelligent to automaticcaly identify the employee\_id from the document, make it as \_id and insert the record.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [April 11, 2019, 7:38pm UTC](https://discuss.elastic.co/t/how-to-create-an-index-in-es6-that-automatically-assigns-a-field-value-ex-employee-id-found-inside-a-document-to-id-document-id-each-time-a-new-document-is-inserted/176425/5 "2019-04-11T19:38:03Z")

</div>

If you are on Elasticsearch 6.5 or higher you can define a [default pipeline for the index](https://www.elastic.co/guide/en/elasticsearch/reference/6.5/index-modules.html#dynamic-index-settings).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 12, 2019, 12:44am UTC](https://discuss.elastic.co/t/how-to-create-an-index-in-es6-that-automatically-assigns-a-field-value-ex-employee-id-found-inside-a-document-to-id-document-id-each-time-a-new-document-is-inserted/176425/6 "2019-04-12T00:44:10Z")

</div>

Great. I didn't know that this was merged. 😉

---

<div class="post-metadata">

**Author:** ![Nandan\_Reddy\_V](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nandan_reddy_v/32/43948_2.png) [@Nandan\_Reddy\_V](https://discuss.elastic.co/u/Nandan_Reddy_V)\
**Post date:** [April 12, 2019, 2:16am UTC](https://discuss.elastic.co/t/how-to-create-an-index-in-es6-that-automatically-assigns-a-field-value-ex-employee-id-found-inside-a-document-to-id-document-id-each-time-a-new-document-is-inserted/176425/7 "2019-04-12T02:16:19Z")

</div>

Thanks Christian, for letting me know this possibility. This would help us in solving a long standing issue. Can you please share a code snippet (or) example (or) steps on how "index.default\_pipeline" can be included while index creation.

I appreciate your help in advance.

---

<div class="post-metadata">

**Author:** ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)\
**Post date:** [April 12, 2019, 3:51am UTC](https://discuss.elastic.co/t/how-to-create-an-index-in-es6-that-automatically-assigns-a-field-value-ex-employee-id-found-inside-a-document-to-id-document-id-each-time-a-new-document-is-inserted/176425/8 "2019-04-12T03:51:29Z")

</div>

Hi,

Here how to add a default\_pipline settings on an index.

```
PUT /YOUR_INDEX/_settings
{
    "index" : {
        "default_pipeline" : "YOUR_PIPELINE_NAME"
    }
}

```

doc is here: [Update Indices Settings | Elasticsearch Guide [6.5] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/6.5/indices-update-settings.html)

As it's a dynamic setting it will apply without any other manipulation.

> dynamic
> 
> They can be changed on a live index using the [update-index-settings](https://www.elastic.co/guide/en/elasticsearch/reference/6.5/indices-update-settings.html) API.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [April 12, 2019, 5:12am UTC](https://discuss.elastic.co/t/how-to-create-an-index-in-es6-that-automatically-assigns-a-field-value-ex-employee-id-found-inside-a-document-to-id-document-id-each-time-a-new-document-is-inserted/176425/9 "2019-04-12T05:12:29Z")

</div>

If you are using time-based indices you can also apply it via an index template.

---

<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:** [May 10, 2019, 5:12am UTC](https://discuss.elastic.co/t/how-to-create-an-index-in-es6-that-automatically-assigns-a-field-value-ex-employee-id-found-inside-a-document-to-id-document-id-each-time-a-new-document-is-inserted/176425/10 "2019-05-10T05:12:30Z")

</div>

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