# Date format high level rest client 6.2

**URL:** <https://discuss.elastic.co/t/date-format-high-level-rest-client-6-2/130091>\
**Category:** Elasticsearch\
**Created:** [May 1, 2018, 6:54am UTC](https://discuss.elastic.co/t/date-format-high-level-rest-client-6-2/130091 "2018-05-01T06:54:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Omprakash\_Verma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/omprakash_verma/32/42589_2.png) [@Omprakash\_Verma](https://discuss.elastic.co/u/Omprakash_Verma)\
**Post date:** [May 1, 2018, 6:54am UTC](https://discuss.elastic.co/t/date-format-high-level-rest-client-6-2/130091/1 "2018-05-01T06:54:40Z")

</div>

Hi, I am facing one issue related to date format in ES response. When I index data, it is mapped as text, how can I specify the mappings before or at the time of indexing the data.

If I call the mappings api before indexing, then it says indices not found.

Thanks...

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 1, 2018, 7:06am UTC](https://discuss.elastic.co/t/date-format-high-level-rest-client-6-2/130091/2 "2018-05-01T07:06:37Z")

</div>

Share what you tried

---

<div class="post-metadata">

**Author:** ![Omprakash\_Verma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/omprakash_verma/32/42589_2.png) [@Omprakash\_Verma](https://discuss.elastic.co/u/Omprakash_Verma)\
**Post date:** [May 1, 2018, 5:41pm UTC](https://discuss.elastic.co/t/date-format-high-level-rest-client-6-2/130091/3 "2018-05-01T17:41:14Z")

</div>

This is the code I am using to insert the index :

```auto
BulkRequest request = new BulkRequest();
request.timeout(TimeValue.timeValueMinutes(2));

try {
	
	records.forEach(record -> {
		IndexRequest indexRequest = new IndexRequest("index", "prd", record.id()).source(record);
    		request.add(indexRequest);
	});
	
	restHighLevelClient.bulk(request);
	
} catch (ElasticsearchException e) {
	e.printStackTrace();
	logger.info("@ElasticSearch Index error ", e.getMessage());
} catch (java.io.IOException ex) {
	ex.printStackTrace();
	logger.info("@ElasticSearch io Index error ", ex.getMessage());
}

```

When index are inserted all the date fields like start\_datetime, end\_datetime, created\_at are mapped as text. In the json, date comes in format like

```auto
"start_datetime": "2017-11-30T10:30-08:00[America/Los_Angeles]",

```

I tried to send put request to update the mappings too by using below request.  
URL : https://$ES\_URL/index/prd/\_mapping

```auto
 {
 	"properties": {
 		"start_datetime": {
 			"type": "date",
 			"format": "strict_date_optional_time"
 		}
 	}
 }

```

But it did not work. Error thrown -\> "mapper [start\_datetime] of different type, current\_type [text], merged\_type [date]"

What changes I need to get the date in proper format. I mean without zone info.

Thanks

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 1, 2018, 6:23pm UTC](https://discuss.elastic.co/t/date-format-high-level-rest-client-6-2/130091/4 "2018-05-01T18:23:39Z")

</div>

`record` seems to be an object. Not a String.

BTW use `.source(jsonString, XContentType.JSON)` instead.

---

<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:** [May 29, 2018, 6:33pm UTC](https://discuss.elastic.co/t/date-format-high-level-rest-client-6-2/130091/5 "2018-05-29T18:33:47Z")

</div>

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