# Is it possible to have a custom document\_id in Logstash?

**URL:** <https://discuss.elastic.co/t/is-it-possible-to-have-a-custom-document-id-in-logstash/69543>\
**Category:** Logstash\
**Created:** [December 20, 2016, 9:47am UTC](https://discuss.elastic.co/t/is-it-possible-to-have-a-custom-document-id-in-logstash/69543 "2016-12-20T09:47:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kulasangar\_Gowrisang](https://avatars.discourse-cdn.com/v4/letter/k/ce73a5/32.png) [@Kulasangar\_Gowrisang](https://discuss.elastic.co/u/Kulasangar_Gowrisang)\
**Post date:** [December 20, 2016, 9:47am UTC](https://discuss.elastic.co/t/is-it-possible-to-have-a-custom-document-id-in-logstash/69543/1 "2016-12-20T09:47:41Z")

</div>

I'm having two `jdbc` filters (but the same connection parameters, apart from the `MySQL` query) in my `input` part where i'm trying to get data from the database and push it to the index. As I said the only difference in both of those jdbc connections is the MySQL query, where I'm trying to get data from two different tables (primary key for both is a column named `id`).

What i'm trying to do is to push both the data to a single index, where I'm trying to differentiate both the table records by the `document_id`. So I'm trying to filter both the jdbc connections by `type` in the `output` and assign `document_id` with a prefix so that I could search from ES using the `document_id`:

```
if [type] == "sms1"{
	elasticsearch {
	        index => "test1"
		document_type => "message_logs"
		document_id => "sms1_%{id}" <-- id is the primary key
		action => index
		hosts => "myhost"
	}
} else {
	elasticsearch {
		index => "test1"
		document_type => "message_logs"
		document_id => "sms2_%{id}" <-- id is the primary key
		action => index
		hosts => "myhost"
	}
}

```

Is it possible to add a prefix as such to the `document_id`, or is there any other way I can handle this? Any help could be appreciated.

---

<div class="post-metadata">

**Author:** ![jsvd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jsvd/32/6203_2.png) [@jsvd](https://discuss.elastic.co/u/jsvd)\
**Post date:** [December 20, 2016, 11:27am UTC](https://discuss.elastic.co/t/is-it-possible-to-have-a-custom-document-id-in-logstash/69543/2 "2016-12-20T11:27:14Z")

</div>

I'm not fully sure I understand the question, but you could just do

```auto
output {
	elasticsearch {
		index => "test1"
		document_type => "message_logs"
		document_id => "%{type}-%{id}"
		action => index
		hosts => "myhost"
	}
}

```

this way you only need one output that will generate ids based on the `type` and `id` fields.

---

<div class="post-metadata">

**Author:** ![Kulasangar\_Gowrisang](https://avatars.discourse-cdn.com/v4/letter/k/ce73a5/32.png) [@Kulasangar\_Gowrisang](https://discuss.elastic.co/u/Kulasangar_Gowrisang)\
**Post date:** [December 20, 2016, 11:36am UTC](https://discuss.elastic.co/t/is-it-possible-to-have-a-custom-document-id-in-logstash/69543/3 "2016-12-20T11:36:18Z")

</div>

My above configuration worked. Your suggestion looks even more better and clear 🙂

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:** [January 17, 2017, 11:36am UTC](https://discuss.elastic.co/t/is-it-possible-to-have-a-custom-document-id-in-logstash/69543/4 "2017-01-17T11:36:19Z")

</div>

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