# How to set my own field value as @timestamp

**URL:** <https://discuss.elastic.co/t/how-to-set-my-own-field-value-as-timestamp/77366>\
**Category:** Logstash\
**Created:** [March 3, 2017, 9:40pm UTC](https://discuss.elastic.co/t/how-to-set-my-own-field-value-as-timestamp/77366 "2017-03-03T21:40:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sharon.c](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sharon.c/32/16076_2.png) [@sharon.c](https://discuss.elastic.co/u/sharon.c)\
**Post date:** [March 3, 2017, 9:40pm UTC](https://discuss.elastic.co/t/how-to-set-my-own-field-value-as-timestamp/77366/1 "2017-03-03T21:40:48Z")

</div>

I am porting data from Mysql to Elasticsearch using logtash 5.2  
I need to have a field named record\_time as the timestamp in Elasticsearch, I used date filter, and it does not work, and there is no warning.

```
input {
  jdbc {
    jdbc_driver_library => "./mysql-connector-java-5.1.36.jar"
    jdbc_driver_class => "com.mysql.jdbc.Driver"
    jdbc_connection_string => "jdbc:mysql://myserver:port/mundotrack?zeroDateTimeBehavior=convertToNull"
    jdbc_user => "user"
    jdbc_password => "pass"
    jdbc_page_size => 10
    jdbc_paging_enabled => true
    statement => " select * from mytable order by record_time limit 10 "
  }
}

   filter {
           date {
                 match => ["record_time","yyyy-MM-dd'T'HH:mm:ss.SSSZ", "ISO8601", "UNIX_MS","UNIX", "yyyy-MM-dd HH:mm:ss"]
                timezone => "America/Toronto"
                locale => "en"
                target => "@timestamp"
           }
   }
   
output {
  elasticsearch {
      hosts => ["myhost"]
      index => "myindex"  
      template_name => "mytemplate"
   }
}

```

This is when I print out the record\_time field using  
`stdout { codec => json }`

![](https://us1.discourse-cdn.com/elastic/original/3X/b/c/bc95b3b5a3b3a8fb357c448bcdc517e94c2a72d9.png)

.  
.  
The template is defined as

```
PUT /_template/mytemplate
{
   "template": "myindex*",
   "order" : 2,
   "settings": {
        "number_of_shards" : 2,  
        "number_of_replicas" : 1
    },
       "mappings" : {
        "log" : {
          "_all" : {"enabled" : false, "omit_norms" : true},
          "dynamic_templates" : [  
           {
            "string_fields" : {
              "match" : "*",
              "match_mapping_type" : "string",
              "mapping" : {
               "type" : "string",
    	       "index": "no"
              }
            }
          }
          ]
         }
      }
    }

```

I am not new to this filter, it works pretty good when when I used filebeat to forward data to logstash. But when I directly get data from mysql, it has problems.

---

<div class="post-metadata">

**Author:** ![sharon.c](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sharon.c/32/16076_2.png) [@sharon.c](https://discuss.elastic.co/u/sharon.c)\
**Post date:** [March 3, 2017, 11:04pm UTC](https://discuss.elastic.co/t/how-to-set-my-own-field-value-as-timestamp/77366/2 "2017-03-03T23:04:28Z")

</div>

Problem solved,  
I modified the Mysql query

> 

Select  
DATE\_FORMAT(record\_time, '%Y-%m-%d %T') record\_time, ...

Then I used this code in logstash

```
      date {
           match => ["record_time","YYYY-MM-dd HH:mm:ss"]
           timezone => "America/Toronto"
           locale => "en"
           target => "@timestamp"
      } 

```

It works.

---

<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 31, 2017, 11:04pm UTC](https://discuss.elastic.co/t/how-to-set-my-own-field-value-as-timestamp/77366/3 "2017-03-31T23:04:28Z")

</div>

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