# Unable to convert fields into DATE type in Logstash

**URL:** <https://discuss.elastic.co/t/unable-to-convert-fields-into-date-type-in-logstash/310830>\
**Category:** Logstash\
**Created:** [July 28, 2022, 8:12am UTC](https://discuss.elastic.co/t/unable-to-convert-fields-into-date-type-in-logstash/310830 "2022-07-28T08:12:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mangeshmj1992](https://avatars.discourse-cdn.com/v4/letter/m/d9b06d/32.png) [@mangeshmj1992](https://discuss.elastic.co/u/mangeshmj1992)\
**Post date:** [July 28, 2022, 8:12am UTC](https://discuss.elastic.co/t/unable-to-convert-fields-into-date-type-in-logstash/310830/1 "2022-07-28T08:12:21Z")

</div>

Hello team,  
I am unbale to convert field into data type. Can you please help me on this. Format is coming as Text only

Sample Log:

```auto
CIG,CCI05_05_NRW_22102020043728_000014635.txt,26/07/2022 04:37:50,26/07/2022 04:42:12,CCI05_05_NRW_22102020043728_000014635.txt,26-07-2022 03:00,26-07-2022 04:42,CCI05_05_NRW_22102020043728_000014635.txt,04:42:33,,,SENT_FROM_BPM,,,,,

```

GROK:

```auto
%{GREEDYDATA},\s*%{DATE:date1}\s*%{TIME:time1}\,\s*%{DATE:date2}\s*%{TIME:time2}

```

Logstash Conf:

```auto
input {
  beats {
    port => 5044
  }
}

filter {
	grok {
	 match => { "message" => "%{GREEDYDATA},\s*%{DATE:date1}\s*%{TIME:time1}\,\s*%{DATE:date2}\s*%{TIME:time2}"
	 }
	 }
		mutate {
			add_field => {
				"Source_Creation_Date" => "%{date1} %{time1}"
				"Source_updation_Date" => "%{date2} %{time2}"
			}
		}
			date {
				match => ["Source_Creation_Date", "dd/MM/yyyy HH:mm:ss", "dd/MM/yyyy HH:mm:ss"]
      }
	  date {
				match => ["Source_updation_Date", "dd/MM/yyyy HH:mm:ss", "dd/MM/yyyy HH:mm:ss"]
      }
    }

output {
  elasticsearch {
   hosts => ["http://localhost:9200"]
   index => "testindexdata6"
  }
  stdout { codec => rubydebug }
}

```

---

<div class="post-metadata">

**Author:** ![Ofir\_Edi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ofir_edi/32/78181_2.png) [@Ofir\_Edi](https://discuss.elastic.co/u/Ofir_Edi)\
**Post date:** [July 28, 2022, 10:35am UTC](https://discuss.elastic.co/t/unable-to-convert-fields-into-date-type-in-logstash/310830/2 "2022-07-28T10:35:28Z")

</div>

Hi @mangeshmj1992  
date filter in Logstash is used to override @timestamp field with other value to your choice.  
If you want Elasticseach to treat Source\_Creation\_Date and Source\_updation\_Date as dates then you can set the appropriate mapping when creating the index (using index template or manually).  
e.g. manually (using kibana dev tools - if index exists delete it first as mapping cannot be changed):  
PUT testindexdata6

```auto
{
  "mappings": {
    "properties": {
      "Source_Creation_Date": {
        "type": "date",
        "format": "dd/MM/yyyy HH:mm:ss"
      },
      "Source_updation_Date": {
        "type": "date",
        "format": "dd/MM/yyyy HH:mm:ss"
      }
    }
  }
}

```

- You can remove date filters from Logstash pipeline
- Bear in mind that you are not using timezone which can be fine if your data is from same timezone but is less recommended. Elasticsearch & Kibana "now" operator is always compared to UTC 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 25, 2022, 10:35am UTC](https://discuss.elastic.co/t/unable-to-convert-fields-into-date-type-in-logstash/310830/3 "2022-08-25T10:35:39Z")

</div>

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