# Composite ID

**URL:** <https://discuss.elastic.co/t/composite-id/115284>\
**Category:** Logstash\
**Created:** [January 12, 2018, 11:44am UTC](https://discuss.elastic.co/t/composite-id/115284 "2018-01-12T11:44:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![devil\_srj7](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@devil\_srj7](https://discuss.elastic.co/u/devil_srj7)\
**Post date:** [January 12, 2018, 11:44am UTC](https://discuss.elastic.co/t/composite-id/115284/1 "2018-01-12T11:44:17Z")

</div>

I require a way to create a composite key for the document in elastic search through logstash corresponding to the composite key in my MySQL database.

---

<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:** [January 12, 2018, 12:26pm UTC](https://discuss.elastic.co/t/composite-id/115284/2 "2018-01-12T12:26:50Z")

</div>

I believe it's more a #logstash question so I moved your question.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [January 16, 2018, 4:36pm UTC](https://discuss.elastic.co/t/composite-id/115284/3 "2018-01-16T16:36:42Z")

</div>

Assuming you have the key in a field in each event, just reference that field with the `%{fieldname}` notation in the elasticsearch output's `document_id` option.

---

<div class="post-metadata">

**Author:** ![devil\_srj7](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@devil\_srj7](https://discuss.elastic.co/u/devil_srj7)\
**Post date:** [January 17, 2018, 9:26am UTC](https://discuss.elastic.co/t/composite-id/115284/4 "2018-01-17T09:26:27Z")

</div>

Thanks!

---

<div class="post-metadata">

**Author:** ![devil\_srj7](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@devil\_srj7](https://discuss.elastic.co/u/devil_srj7)\
**Post date:** [January 17, 2018, 11:34am UTC](https://discuss.elastic.co/t/composite-id/115284/5 "2018-01-17T11:34:04Z")

</div>

> [@magnusbaeck](#):
>
> Assuming you have the key in a field in each event, just reference that field with the %{fieldname} notation in the elasticsearch output's document\_id option.

But by using document\_id, we would be rewriting elasticsearch default id section.  
My requirement is as follow

![Screenshot (1)](https://us1.discourse-cdn.com/elastic/original/3X/a/a/aabc697df0fec67835857020658268ee0049bf32.png)

This is the description of my table, and i need the primary key associated with this table as it is in my elasticsearch.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [January 23, 2018, 11:35am UTC](https://discuss.elastic.co/t/composite-id/115284/6 "2018-01-23T11:35:26Z")

</div>

> But by using document\_id, we would be rewriting elasticsearch default id section.

Yes. What's the problem with that?

If you for some reason want to keep ES's autogenerated document id but additionally have your own field that acts as a document key that's fine too, just use a mutate filter to add a new field with the contents of the other fields.

---

<div class="post-metadata">

**Author:** ![devil\_srj7](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@devil\_srj7](https://discuss.elastic.co/u/devil_srj7)\
**Post date:** [January 23, 2018, 12:27pm UTC](https://discuss.elastic.co/t/composite-id/115284/7 "2018-01-23T12:27:46Z")

</div>

Thanks

---

<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:** [February 20, 2018, 12:27pm UTC](https://discuss.elastic.co/t/composite-id/115284/8 "2018-02-20T12:27:54Z")

</div>

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