# Cannot write xcontent for unknown value of type class java.time.OffsetDateTime error

**URL:** <https://discuss.elastic.co/t/cannot-write-xcontent-for-unknown-value-of-type-class-java-time-offsetdatetime-error/231148>\
**Category:** Elasticsearch\
**Created:** [May 5, 2020, 12:36pm UTC](https://discuss.elastic.co/t/cannot-write-xcontent-for-unknown-value-of-type-class-java-time-offsetdatetime-error/231148 "2020-05-05T12:36:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Siddharth1010](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@Siddharth1010](https://discuss.elastic.co/u/Siddharth1010)\
**Post date:** [May 5, 2020, 12:36pm UTC](https://discuss.elastic.co/t/cannot-write-xcontent-for-unknown-value-of-type-class-java-time-offsetdatetime-error/231148/1 "2020-05-05T12:36:38Z")

</div>

I am able to search from elasticsearch database where the date is between two specified dates

Here is the part of my code

```auto
       SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
       searchSourceBuilder.size(10000);
       searchSourceBuilder.query(QueryBuilders.rangeQuery("operation_timestamp_start").gte(date1).lte(date2));
       firstSearchRequest.source(searchSourceBuilder);

```

Here date1 and date2 variables are java variables of type OffsetDateTime while the `operation_timestamp_start` variable in elasticsearch databse is of type date.

I am getting the following error - `java.lang.IllegalArgumentException: cannot write xcontent for unknown value of type class java.time.OffsetDateTime`

Is this because I should use a Date variable instead of offsetDateTime. If yes, how should I accomodate the OffsetDate Part

---

<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:** [June 2, 2020, 12:36pm UTC](https://discuss.elastic.co/t/cannot-write-xcontent-for-unknown-value-of-type-class-java-time-offsetdatetime-error/231148/2 "2020-06-02T12:36:46Z")

</div>

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