# Logstash jdbc input keep sql field ordering in place

**URL:** <https://discuss.elastic.co/t/logstash-jdbc-input-keep-sql-field-ordering-in-place/123780>\
**Category:** Logstash\
**Created:** [March 13, 2018, 4:49pm UTC](https://discuss.elastic.co/t/logstash-jdbc-input-keep-sql-field-ordering-in-place/123780 "2018-03-13T16:49:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ramzey1981](https://avatars.discourse-cdn.com/v4/letter/r/d26b3c/32.png) [@ramzey1981](https://discuss.elastic.co/u/ramzey1981)\
**Post date:** [March 13, 2018, 4:49pm UTC](https://discuss.elastic.co/t/logstash-jdbc-input-keep-sql-field-ordering-in-place/123780/1 "2018-03-13T16:49:00Z")

</div>

hey team,

I have the following logstash config file,

jdbc {  
jdbc\_driver\_library =\> "C:\Program Files\sqljdbc\_6.2\enu\mssql-jdbc-6.2.2.jre8.jar"  
jdbc\_driver\_class =\> "com.microsoft.sqlserver.jdbc.SQLServerDriver"  
jdbc\_connection\_string =\> "jdbc:sqlserver://xxxxxx.xxxxx..xx\Strongmail:1433"  
jdbc\_user =\> "xxx"  
jdbc\_password =\> "xxxxxxxxxx"  
sql\_log\_level =\> "debug"  
lowercase\_column\_names =\> "false"  
schedule =\> "\*/1 \* \* \* \*"  
use\_column\_value =\> true  
tracking\_column =\> recordId  
last\_run\_metadata\_path =\> "logstash\_jdbc\_last\_run\_SM\_SUCCESS\_LOG"  
statement =\> "exec strongmail.dbo.CRM\_EMAIL\_DELIVERY\_LOGS\_GET :sql\_last\_value, null"  
}  
}

output {  
stdout { codec =\> json }

```
            #file {
            # path => "f:/logstash_output_logs/test1.log"
            #}

            #stdout {codec => rubydebug}

```

}

put When the sql output get printed to standard output the ordering of the sql statement changes, how do we we the output of the jdbc input to the same as the ordering in the actual stored proc in SQl server. Basically we want the timestamp to the be the first field.

thanks

---

<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:** [March 13, 2018, 6:46pm UTC](https://discuss.elastic.co/t/logstash-jdbc-input-keep-sql-field-ordering-in-place/123780/2 "2018-03-13T18:46:30Z")

</div>

Fields in Logstash events are not ordered. If there's a JSON serializing Ruby gem that allows you to customize the order it serializes fields you could fork and adjust the json codec to use that gem.

---

<div class="post-metadata">

**Author:** ![ramzey1981](https://avatars.discourse-cdn.com/v4/letter/r/d26b3c/32.png) [@ramzey1981](https://discuss.elastic.co/u/ramzey1981)\
**Post date:** [March 13, 2018, 7:02pm UTC](https://discuss.elastic.co/t/logstash-jdbc-input-keep-sql-field-ordering-in-place/123780/3 "2018-03-13T19:02:52Z")

</div>

thanks magnus,

what is exactly undoing the order, is it the jdbc plugin or the output plugin?

thanks

---

<div class="post-metadata">

**Author:** ![ramzey1981](https://avatars.discourse-cdn.com/v4/letter/r/d26b3c/32.png) [@ramzey1981](https://discuss.elastic.co/u/ramzey1981)\
**Post date:** [March 13, 2018, 7:11pm UTC](https://discuss.elastic.co/t/logstash-jdbc-input-keep-sql-field-ordering-in-place/123780/4 "2018-03-13T19:11:16Z")

</div>

is there any way for me to get the timestamp field from sql to be the first field in the output?

thanks

---

<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:** [March 13, 2018, 9:20pm UTC](https://discuss.elastic.co/t/logstash-jdbc-input-keep-sql-field-ordering-in-place/123780/5 "2018-03-13T21:20:55Z")

</div>

> what is exactly undoing the order, is it the jdbc plugin or the output plugin?

It's Logstash's internal representation of an event that doesn't maintain field ordering.

> is there any way for me to get the timestamp field from sql to be the first field in the output?

As I said: If there's a JSON serializing Ruby gem that allows you to customize the order it serializes fields you could fork and adjust the json codec to use that gem.

---

<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:** [April 10, 2018, 9:21pm UTC](https://discuss.elastic.co/t/logstash-jdbc-input-keep-sql-field-ordering-in-place/123780/6 "2018-04-10T21:21:11Z")

</div>

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