# Elastic search considers date field send by java service as string

**URL:** <https://discuss.elastic.co/t/elastic-search-considers-date-field-send-by-java-service-as-string/251924>\
**Category:** Elasticsearch\
**Created:** [October 13, 2020, 2:58pm UTC](https://discuss.elastic.co/t/elastic-search-considers-date-field-send-by-java-service-as-string/251924 "2020-10-13T14:58:54Z")\
**Posts on this page:** 4\
**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:** [October 13, 2020, 2:58pm UTC](https://discuss.elastic.co/t/elastic-search-considers-date-field-send-by-java-service-as-string/251924/1 "2020-10-13T14:58:54Z")

</div>

Hi I have created a java service and i am indexing the response into elasticseaarch i am sending a date value but elasticsearch considers it as string. Code is already deployed in production. How to change the incoming field i should inform elastic search to consider it as a datefield?

```
          "producercode" : "B39882",
          "send" : "Y",
          "open" : "",
          "timestamp" : "Mon Oct 12 07:29:59 PDT 2020"

```

Is der any possibility of creating pipeline if index name contains prefix like this "notification-service-track-" It should convert this and should index this as a datefield.

Note: We are creating a date based index so by using index API java we are creating index hence index mapping is created by elasticsearch only

---

<div class="post-metadata">

**Author:** ![AClerk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aclerk/32/55297_2.png) [@AClerk](https://discuss.elastic.co/u/AClerk)\
**Post date:** [October 14, 2020, 12:31am UTC](https://discuss.elastic.co/t/elastic-search-considers-date-field-send-by-java-service-as-string/251924/2 "2020-10-14T00:31:43Z")

</div>

Create mappings and let elastic know it is a date.

---

<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:** [October 15, 2020, 5:56am UTC](https://discuss.elastic.co/t/elastic-search-considers-date-field-send-by-java-service-as-string/251924/3 "2020-10-15T05:56:46Z")

</div>

It is a date based index every day index name change dynamically. So instead of using **new Date()** directly i have converted the dateformat to "yyyy-MM-dd'T'HH:mm:ssZ" in my java service now elasticsearch considers it as a date field but this leads to code change.

```auto
    SimpleDateFormat elkTimestamp = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
    String elkTime = elkTimestamp.format(new Date());

```

---

<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:** [November 12, 2020, 5:56am UTC](https://discuss.elastic.co/t/elastic-search-considers-date-field-send-by-java-service-as-string/251924/4 "2020-11-12T05:56:54Z")

</div>

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