We get an error of the Elasticsearch by saving a BusinessObject over the ivy.repo with a field of type Map< String,String >.

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]"}

The problem ist clear. The field "details.data.Value1" is a date field and i try to store a String.

But the definition of our BusinessObject is different to that!
The field "data" of the "detail" object is defined as a Map< String,String >.
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).

JobDetail detail = new JobDetail();
Helper helper = new Helper();
helper.setParam("Value1", (new Date()).toString());
detail.data = helper.getParams();

detail = new JobDetail();
helper.setParam("Value1", "foo");
detail.data = helper.getParams();

Why does Elasticsearch change the given attribute to a date field, although we just fill in String values?
Furthermore we defined the value as a Map of Sting-String value pairs.
Is there a solution of this issue?

We decided not to use JSON objects instead of our Map, because of the easy handling in further uses.

asked 31.07.2019 at 04:33

Adrian%20Imfeld's gravatar image

Adrian Imfeld
accept rate: 77%

edited 26.08.2019 at 10:05

Hi Adrian

As it looks like Elasticsearch converts the result of ch.ivyteam.ivy.scripting.objects.Date.toString() 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.

To avoid this problem you have two possibilities:

  1. Overwrite the Elasticsearch template and redefine the field as String type.
  2. Don't use the ch.ivyteam.ivy.scripting.objects.Date but the java.util.Date class. Elasticsearch doesn't recognize the format in toString() automatically - or you can write your own Date output format with SimpleDateFormat (which goes into the same direction).

I recommend solution 2.


answered 05.08.2019 at 02:36

Andreas%20Rusch's gravatar image

Andreas Rusch
accept rate: 92%

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());

Sorry, but for me it looks like a bug in ivy.

(26.08.2019 at 10:03) Adrian Imfeld Adrian%20Imfeld's gravatar image
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 31.07.2019 at 04:33

Seen: 12,057 times

Last updated: 26.08.2019 at 10:05