# Set order to elasticsearch fields using logstash

**URL:** <https://discuss.elastic.co/t/set-order-to-elasticsearch-fields-using-logstash/219620>\
**Category:** Logstash\
**Created:** [February 17, 2020, 12:46pm UTC](https://discuss.elastic.co/t/set-order-to-elasticsearch-fields-using-logstash/219620 "2020-02-17T12:46:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mohan\_vel](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@Mohan\_vel](https://discuss.elastic.co/u/Mohan_vel)\
**Post date:** [February 17, 2020, 12:46pm UTC](https://discuss.elastic.co/t/set-order-to-elasticsearch-fields-using-logstash/219620/1 "2020-02-17T12:46:37Z")

</div>

Hi Below is my config i am trying to index the data from MSSQL to Elasticsearch using Logstash but field order is getting changed after getting indexed into elasticsearch.

```
input {
    jdbc {
    jdbc_driver_library => "D:\Users\mmurugesan\Desktop\driver\mssql-jdbc-7.4.1.jre12-shaded.jar"
    jdbc_driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"
    jdbc_connection_string => "jdbc:sqlserver://EC2AMAZ-J90JR4A\SQLEXPRESS:1433;databaseName=xxxx;"
    jdbc_user => "xxx"
    jdbc_password => "xxxx"
    jdbc_paging_enabled => true
    tracking_column => modified_date
    use_column_value => true
    clean_run => true
    tracking_column_type => "timestamp"
    schedule => "*/1 * * * *"
    statement => "Select pl.Policyholdername,pl.Age,pl.Dob,pl.Client_Address,cl.claimnumber,cl.claimtype,cl.is_active,cl.Modified_date from claim cl
    inner join Policy pl on pl.Policynumber=cl.policynumber
    where cl.Modified_date >:sql_last_value"
    last_run_metadata_path => "D:\Users\mmurugesan\Desktop\logstash-7.5.2\jdbc_lastrun\jdbc_last_run.txt"
    jdbc_default_timezone => "UTC" 
    }
    }
    filter {
    if [is_active] {
            mutate {    
                add_field => {
                    "[@metadata][elasticsearch_action]" => "index"
                }
            }
            mutate {
                remove_field => ["is_active","@version","@timestamp"]
            }
           
        } else {
            mutate {    
                add_field => {
                    "[@metadata][elasticsearch_action]" => "delete"
                }
            }
            mutate {
                remove_field => ["is_active","@version","@timestamp"]
            }
        } 
    	
    }
    output {
    elasticsearch {
    hosts => "xxx"
    user => "xxx"
    password => "xxx"
    index => "duckcreek"
    action => "%{[@metadata][elasticsearch_action]}"
    document_type => "_doc"
    document_id => "%{claimnumber}"

    }
    stdout { codec => rubydebug }
    }

```

Screen shot given for reference

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/e/8/e86ce0fc4687d0601b7c20164e574e5fd7cf47ee.png)

How to set the field order as given in the select statement in my config?  
Also i need to know how to change the date format using logstash?

Could some one help me to solve above queries? Thanks in advance

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [February 17, 2020, 3:10pm UTC](https://discuss.elastic.co/t/set-order-to-elasticsearch-fields-using-logstash/219620/2 "2020-02-17T15:10:56Z")

</div>

> [@Mohan\_vel](#):
>
> field order is getting changed after getting indexed into elasticsearch

Neither logstash nor elasticsearch have ordered fields.

---

<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 17, 2020, 4:21am UTC](https://discuss.elastic.co/t/set-order-to-elasticsearch-fields-using-logstash/219620/4 "2020-03-17T04:21:10Z")

</div>

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