# Get only the last record

**URL:** <https://discuss.elastic.co/t/get-only-the-last-record/75320>\
**Category:** Logstash\
**Created:** [February 16, 2017, 11:34am UTC](https://discuss.elastic.co/t/get-only-the-last-record/75320 "2017-02-16T11:34:11Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mano\_even](https://avatars.discourse-cdn.com/v4/letter/m/6de8d8/32.png) [@mano\_even](https://discuss.elastic.co/u/mano_even)\
**Post date:** [February 16, 2017, 11:34am UTC](https://discuss.elastic.co/t/get-only-the-last-record/75320/1 "2017-02-16T11:34:11Z")

</div>

Hello ,

Im using logstash and jdbc driver to import my data to ES.

but when i look for data using ,i only find the last record?

my conf:

input {  
jdbc {  
jdbc\_connection\_string =\> "jdbc:sqlserver:myconnexion;databaseName=mydb"  
jdbc\_user =\> "myusername"  
jdbc\_password =\> "mypass"  
jdbc\_driver\_library =\> "D:\ES\sqljdbc42.jar"  
jdbc\_driver\_class =\> "com.microsoft.sqlserver.jdbc.SQLServerDriver"  
statement =\> "sql statement"

}  
}  
filter {

}  
output {  
stdout { codec =\> rubydebug }  
elasticsearch {  
#protocol =\> http  
index =\> "myindex"  
document\_type =\> "mytype"  
document\_id =\> "%{myid}"  
hosts =\> "localhost"

```
    }

```

}

---

<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:** [February 16, 2017, 2:20pm UTC](https://discuss.elastic.co/t/get-only-the-last-record/75320/2 "2017-02-16T14:20:36Z")

</div>

Does the SQL query return a column named `myid` or are you creating that field elsewhere? It probably doesn't so all documents get the same document id, overwriting each other all the time.

---

<div class="post-metadata">

**Author:** ![mano\_even](https://avatars.discourse-cdn.com/v4/letter/m/6de8d8/32.png) [@mano\_even](https://discuss.elastic.co/u/mano_even)\
**Post date:** [February 16, 2017, 3:20pm UTC](https://discuss.elastic.co/t/get-only-the-last-record/75320/3 "2017-02-16T15:20:52Z")

</div>

Thank you for your answer!

yes my sql query return the named column

---

<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:** [February 16, 2017, 3:22pm UTC](https://discuss.elastic.co/t/get-only-the-last-record/75320/4 "2017-02-16T15:22:16Z")

</div>

Please show an example document from Elasticsearch or your `stdout { codec => rubydebug }` output.

---

<div class="post-metadata">

**Author:** ![mano\_even](https://avatars.discourse-cdn.com/v4/letter/m/6de8d8/32.png) [@mano\_even](https://discuss.elastic.co/u/mano_even)\
**Post date:** [February 16, 2017, 3:53pm UTC](https://discuss.elastic.co/t/get-only-the-last-record/75320/5 "2017-02-16T15:53:28Z")

</div>

![](https://us1.discourse-cdn.com/elastic/original/2X/b/b6e6aeaf9c292c50e8d115d8ff35fe8f9efb771b.PNG)

assuming that myid is :BusinessEntityID

---

<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:** [February 16, 2017, 6:44pm UTC](https://discuss.elastic.co/t/get-only-the-last-record/75320/6 "2017-02-16T18:44:33Z")

</div>

Field names are case-sensitive (BusinessEntityID vs. businessentityid).

---

<div class="post-metadata">

**Author:** ![mano\_even](https://avatars.discourse-cdn.com/v4/letter/m/6de8d8/32.png) [@mano\_even](https://discuss.elastic.co/u/mano_even)\
**Post date:** [February 16, 2017, 8:00pm UTC](https://discuss.elastic.co/t/get-only-the-last-record/75320/7 "2017-02-16T20:00:45Z")

</div>

Thank you so much ,for your help !

---

<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:** [March 16, 2017, 8:00pm UTC](https://discuss.elastic.co/t/get-only-the-last-record/75320/8 "2017-03-16T20:00:45Z")

</div>

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