Hi,
I have a document in an index, with the following array indexed (I've
verified that this is what it looks in the index):
tag_ids: [2, 4, 5, 63, 15]
I retrieve this document via a prepareGet():
GetResponse r =
SearchClient.instance().prepareGet(...).setFields(...).execute().actionGet();
The problem occurs when I try to access the tag_ids field:
tags = (List) r.field("tag_ids").getValue();
This results in the following error:
java.lang.ClassCastException: java.lang.Integer cannot be cast to
java.util.List
I've added the following log statement:
Logger.info("CLASS: " + r.field("tag_ids").getValue().getClass().getName()
- ", value: " + r.field("tag_ids").getValue());
Which results in:
CLASS: java.lang.Integer, value: 19
I don't really understand this behaviour. The value 19 is not even in the
array?
What am I doing wrong here?
I've then tried changing from getValue() to getValues():
tags = r.field("tag_ids").getValues();
This then works fine. HOWEVER, after one or more re-indexing rounds of the
document (without changing the contents of tag_ids field), the following
error occurs when accessing the field:
java.lang.NumberFormatException: For input string: "[2, 4, 5, 63, 15]"
This occurs when performing Long.parseLong(o.toString()) where o is an
object in the array. So now the first object in the List retrieved via
getValues() is a String representation of the int array?
I then restart the ElasticSearch server, and the problem goes away for this
document. But as soon as it is re-indexed, the problem reoccurs.
What am I doing wrong here?
What is the correct way of accessing the array from the GetResponse, to get
consistent results?
Thanks for your help!
Best regards,
OGG
--