# Java Timestamp to ElasticSearch Java REST Client 6.6

**URL:** <https://discuss.elastic.co/t/java-timestamp-to-elasticsearch-java-rest-client-6-6/167187>\
**Category:** Elasticsearch\
**Created:** [February 5, 2019, 7:36pm UTC](https://discuss.elastic.co/t/java-timestamp-to-elasticsearch-java-rest-client-6-6/167187 "2019-02-05T19:36:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![clouduser](https://avatars.discourse-cdn.com/v4/letter/c/e95f7d/32.png) [@clouduser](https://discuss.elastic.co/u/clouduser)\
**Post date:** [February 5, 2019, 7:36pm UTC](https://discuss.elastic.co/t/java-timestamp-to-elasticsearch-java-rest-client-6-6/167187/1 "2019-02-05T19:36:09Z")

</div>

I have sample value "1547674800000" which I formated to Java.sql.timestamp and tryng to insert into ELastic Search via Java REST Client.

Timestamp Value :1547674800000

I am getting error

Exception in thread "main" java.lang.IllegalArgumentException: cannot write xcontent for unknown value of type class java.sql.Timestamp  
at org.elasticsearch.common.xcontent.XContentBuilder.unknownValue(XContentBuilder.java:833)  
at org.elasticsearch.common.xcontent.XContentBuilder.map(XContentBuilder.java:888)  
at org.elasticsearch.common.xcontent.XContentBuilder.map(XContentBuilder.java:870)  
at org.elasticsearch.action.index.IndexRequest.source(IndexRequest.java:343)  
at org.elasticsearch.action.index.IndexRequest.source(IndexRequest.java:332)  
at com.JavaConsumer.insertDNSVolume(JavaConsumer.java:106)  
at com.JavaConsumer.main(JavaConsumer.java:178)

---

<div class="post-metadata">

**Author:** ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)\
**Post date:** [February 8, 2019, 9:10am UTC](https://discuss.elastic.co/t/java-timestamp-to-elasticsearch-java-rest-client-6-6/167187/2 "2019-02-08T09:10:32Z")

</div>

hi,  
could you please paste the code for your `com.JavaConsumer.insertDNSVolume` method?

Thanks

---

<div class="post-metadata">

**Author:** ![mcelaya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mcelaya/32/20052_2.png) [@mcelaya](https://discuss.elastic.co/u/mcelaya)\
**Post date:** [February 20, 2019, 10:18am UTC](https://discuss.elastic.co/t/java-timestamp-to-elasticsearch-java-rest-client-6-6/167187/3 "2019-02-20T10:18:58Z")

</div>

Hello,  
I am aware that this is the REST client, but I'm having the same issue with the TransportClient and I suspect it could have the same root.

I am migrating our current client from 5.4.3 to 6.6.0. In my case I'm fetching data from the database and convert the timestamp values from the `oracle.sql.TIMESTAMP` class to `java.sql.Timestamp` - that's how the client's been working for versions 2.3.3 and 5.4.3 and it has been fine so far.

This is how I send the requests to ES:

> BulkProcessor bulkProcessor;  
> [...]  
> for (Map\<String, Object\> document : documents) {  
> IndexRequest request = new IndexRequest(localIndexName, type, id);  
> [...]  
> request.source(document);  
> bulkProcessor.add(request);

And this is the stack trace:

> java.lang.IllegalArgumentException: cannot write xcontent for unknown value of type class java.sql.Timestamp  
> at org.elasticsearch.common.xcontent.XContentBuilder.unknownValue(XContentBuilder.java:833)  
> at org.elasticsearch.common.xcontent.XContentBuilder.map(XContentBuilder.java:888)  
> at org.elasticsearch.common.xcontent.XContentBuilder.map(XContentBuilder.java:870)  
> at org.elasticsearch.action.index.IndexRequest.source(IndexRequest.java:343)  
> at org.elasticsearch.action.index.IndexRequest.source(IndexRequest.java:332)

Let me know if you need any additional information.

Thanks in advance for your help!  
Michael.

---

<div class="post-metadata">

**Author:** ![mcelaya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mcelaya/32/20052_2.png) [@mcelaya](https://discuss.elastic.co/u/mcelaya)\
**Post date:** [February 20, 2019, 10:52am UTC](https://discuss.elastic.co/t/java-timestamp-to-elasticsearch-java-rest-client-6-6/167187/4 "2019-02-20T10:52:26Z")

</div>

Looks like the issue was reported:

> <https://github.com/elastic/elasticsearch/issues/31377>

Not clear whether this will be dealt with or not though. Should I just turn the timestamp into a string like it is suggested in that github thread, though? It doesn't feel the right way of doing it...

Regards,  
Michael.

---

<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 20, 2019, 10:52am UTC](https://discuss.elastic.co/t/java-timestamp-to-elasticsearch-java-rest-client-6-6/167187/5 "2019-03-20T10:52:35Z")

</div>

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