# Logstash document\_id for elasticsearch not incrementing

**URL:** <https://discuss.elastic.co/t/logstash-document-id-for-elasticsearch-not-incrementing/62427>\
**Category:** Logstash\
**Created:** [October 6, 2016, 7:25pm UTC](https://discuss.elastic.co/t/logstash-document-id-for-elasticsearch-not-incrementing/62427 "2016-10-06T19:25:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aja](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@aja](https://discuss.elastic.co/u/aja)\
**Post date:** [October 6, 2016, 7:25pm UTC](https://discuss.elastic.co/t/logstash-document-id-for-elasticsearch-not-incrementing/62427/1 "2016-10-06T19:25:27Z")

</div>

(Running on windows, latest versions of elasticsearch and logstash)  
I've seen a lot of posts with issues (and fixes) about the document\_id with elasticsearch, but none seem to be exactly my problem.... Below is my entire .conf

```
input {
    jdbc {
        # jdbc connection string to our database
        jdbc_connection_string => "jdbc:sqlserver:// ****"
        # The user we wish to execute our statement as
        jdbc_user => " ****"

	jdbc_password => " ****"
        # The path to our downloaded jdbc driver
        jdbc_driver_library => "C:\Program Files\Microsoft JDBC Driver 6.0 for SQL Server\sqljdbc_6.0\enu\sqljdbc41.jar"
        # The name of the driver class for sql
        jdbc_driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"
        # our query
        statement => "select EXID ,Name from myTable"
    }
}
output {
	elasticsearch {
		index => "myIndex"
		document_type => "myType"
		document_id => "%{EXID}"
	}
}

```

The thing is, when I do it like this, it DOES use the EXID as the document\_id......but only the first one. So it grabs the first EXID and uses it as the document\_id for all of them, so at the end, I still only have one document because they all replaced each other because they were all using the same id. If I take the `document_id => "%{EXID}"` line out and use the auto-generated ids, everything works fine. So it is just the delayed expansion that isn't working. What am I doing wrong?

---

<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:** [October 6, 2016, 8:32pm UTC](https://discuss.elastic.co/t/logstash-document-id-for-elasticsearch-not-incrementing/62427/2 "2016-10-06T20:32:58Z")

</div>

That's weird. What if you remove some complexity by using a `stdout { codec => rubydebug }` output? Does the sequence of events look okay (specifically the `EXID` field)?

---

<div class="post-metadata">

**Author:** ![aja](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@aja](https://discuss.elastic.co/u/aja)\
**Post date:** [October 6, 2016, 10:07pm UTC](https://discuss.elastic.co/t/logstash-document-id-for-elasticsearch-not-incrementing/62427/3 "2016-10-06T22:07:30Z")

</div>

looks fine:  
`{ "exid" => 168, "name" => "Name0" } { "exid" => 169, "name" => "Name1" } { "exid" => 170, "name" => "Name2" } { "exid" => 171, "name" => "Name3" }`

The issue was only with document\_id, not the EXID. So when they were all being uploaded with the same document\_id and replacing each other, the EXID field was incrementing as expected. So at the end, I had one document, containing of all the data, including the correct EXID, for the last entry, but with the first EXID for the document\_id

---

<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:** [July 6, 2017, 4:35am UTC](https://discuss.elastic.co/t/logstash-document-id-for-elasticsearch-not-incrementing/62427/4 "2017-07-06T04:35:20Z")

</div>


