# Running Logstash only 1 row affected to elasticsearch

**URL:** <https://discuss.elastic.co/t/running-logstash-only-1-row-affected-to-elasticsearch/141868>\
**Category:** Logstash\
**Created:** [July 27, 2018, 4:20am UTC](https://discuss.elastic.co/t/running-logstash-only-1-row-affected-to-elasticsearch/141868 "2018-07-27T04:20:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dedi\_mi](https://avatars.discourse-cdn.com/v4/letter/d/76d3ee/32.png) [@dedi\_mi](https://discuss.elastic.co/u/dedi_mi)\
**Post date:** [July 27, 2018, 4:20am UTC](https://discuss.elastic.co/t/running-logstash-only-1-row-affected-to-elasticsearch/141868/1 "2018-07-27T04:20:26Z")

</div>

Hi,

I run the logstash via command prompt :  
logstash -f logstash.conf

input {  
jdbc {  
jdbc\_driver\_library =\> "C:\ELASTIC\sqljdbc\_6.0\enu\jre8\sqljdbc42.jar"  
jdbc\_driver\_class =\> "com.microsoft.sqlserver.jdbc.SQLServerDriver"  
jdbc\_connection\_string =\> "jdbc:sqlserver://server;databaseName=database;"  
jdbc\_user =\> "user"  
jdbc\_password =\> "pwd"  
statement =\> "select top 200 \* from table"  
}  
}  
filter {  
}

output {  
elasticsearch {  
hosts =\> ["localhost:9200"]  
index =\> "oph2"  
document\_id =\> "%{id2}"  
}  
stdout { codec =\> rubydebug }  
}

The logstash run well, since i saw the 200 row displayed in command prompt. But when I check in elasticsearch why only 1 row affected to elasticsearch, and the rest 199 were deleted, by checking in Kibana:

"stats": {  
"primaries": {  
"docs": {  
"count": 1,  
"deleted": 199  
},

Is there anyone has the solution regarding this? Why the 199 rows were deleted?  
Thanks in advance

---

<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:** [July 27, 2018, 5:17am UTC](https://discuss.elastic.co/t/running-logstash-only-1-row-affected-to-elasticsearch/141868/2 "2018-07-27T05:17:42Z")

</div>

Check what the ID of the document is in Elasticsearch. If your data does not contain an `id2` field, `document_id => "%{id2}"` will result in all documents getting that exact string `%(id2)` as Id, which will create the document the first time and then update it 199 times.

---

<div class="post-metadata">

**Author:** ![dedi\_mi](https://avatars.discourse-cdn.com/v4/letter/d/76d3ee/32.png) [@dedi\_mi](https://discuss.elastic.co/u/dedi_mi)\
**Post date:** [July 27, 2018, 6:33am UTC](https://discuss.elastic.co/t/running-logstash-only-1-row-affected-to-elasticsearch/141868/3 "2018-07-27T06:33:07Z")

</div>

Hi Christian,

Many thanks for your advice. After I changed the document\_id to the field in my data, all rows were successfully inserted to elasticsearch. thanks for saving my time.

---

<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:** [August 24, 2018, 6:33am UTC](https://discuss.elastic.co/t/running-logstash-only-1-row-affected-to-elasticsearch/141868/4 "2018-08-24T06:33:10Z")

</div>

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