<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: Elasticsearch fail because auto-conversion changes String values into Date</title><link>https://answers.axonivy.com/questions/3903/elasticsearch-fail-because-auto-conversion-changes-string-values-into-date</link><description>&lt;p&gt;We get an error of the Elasticsearch by saving a BusinessObject over the ivy.repo with a field of type &lt;code&gt;Map&amp;lt; String,String &amp;gt;&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Elasticsearch update index of document failed because of: {"root_cause":[{"type":"illegal_argument_exception","reason":"mapper [details.data.Value1] of different type, current_type [text], merged_type [date]"}],"type":"illegal_argument_exception","reason":"mapper [details.data.Value1] of different type, current_type [text], merged_type [date]"}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The problem ist clear. The field "details.data.Value1" is a date field and i try to store a String.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;But&lt;/strong&gt; the definition of our BusinessObject is different to that!&lt;br&gt;
The field "data" of the "detail" object is defined as a &lt;code&gt;Map&amp;lt; String,String &amp;gt;&lt;/code&gt;.&lt;br&gt;
We get this error when we run the following code in an IvyScript (we used a helper class for Maps, because IvyScript is not able to handle double generics).&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;JobDetail detail = new JobDetail();
Helper helper = new Helper();
helper.setParam("Value1", (new Date()).toString());
detail.data = helper.getParams();
job.details.add(detail);

detail = new JobDetail();
helper.setParam("Value1", "foo");
detail.data = helper.getParams();
job.details.add(detail);&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Why does Elasticsearch change the given attribute to a date field, although we just fill in String values?&lt;br&gt;
Furthermore we defined the value as a Map of Sting-String value pairs.&lt;br&gt;
Is there a solution of this issue?&lt;/p&gt;
&lt;p&gt;We decided not to use JSON objects instead of our Map, because of the easy handling in further uses.&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/3903/elasticsearch-fail-because-auto-conversion-changes-string-values-into-date" rel="self"></atom:link><language>en</language><lastBuildDate>Mon, 26 Aug 2019 10:03:03 -0400</lastBuildDate><item><title>Comment by Adrian Imfeld on Andreas Rusch's answer</title><link>https://answers.axonivy.com/questions/3903/elasticsearch-fail-because-auto-conversion-changes-string-values-into-date#3929</link><description>&lt;p&gt;Solution one is not what we want. Solution two works fine.
...but it still makes no sense to me.
The code as follow works:
helper.setParam("Value1", (new Date() as java.util.Date).toString());&lt;/p&gt;
&lt;p&gt;Sorry, but for me it looks like a bug in ivy.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Adrian Imfeld</dc:creator><pubDate>Mon, 26 Aug 2019 10:03:03 -0400</pubDate><guid>https://answers.axonivy.com/questions/3903/elasticsearch-fail-because-auto-conversion-changes-string-values-into-date#3929</guid></item><item><title>Answer by Andreas Rusch</title><link>https://answers.axonivy.com/questions/3903/elasticsearch-fail-because-auto-conversion-changes-string-values-into-date/3904</link><description>&lt;p&gt;Hi Adrian&lt;/p&gt;
&lt;p&gt;As it looks like Elasticsearch converts the result of &lt;code&gt;ch.ivyteam.ivy.scripting.objects.Date.toString()&lt;/code&gt; automatically into a Date type. As much as I know it is not possible to turn off this auto-conversion, most of the time it is a useful feature.&lt;/p&gt;
&lt;p&gt;To avoid this problem you have two possibilities:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Overwrite the Elasticsearch template and redefine the field as String type.&lt;/li&gt;
&lt;li&gt;Don't use the &lt;code&gt;ch.ivyteam.ivy.scripting.objects.Date&lt;/code&gt; but the &lt;code&gt;java.util.Date&lt;/code&gt; class. Elasticsearch doesn't recognize the format in &lt;code&gt;toString()&lt;/code&gt; automatically - or you can write your own Date output format with &lt;code&gt;SimpleDateFormat&lt;/code&gt; (which goes into the same direction).&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;I recommend solution 2.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Andreas Rusch</dc:creator><pubDate>Mon, 05 Aug 2019 02:36:22 -0400</pubDate><guid>https://answers.axonivy.com/questions/3903/elasticsearch-fail-because-auto-conversion-changes-string-values-into-date/3904</guid></item></channel></rss>