[0.19.9 - Java API] Buggy behaviour getting int array from GetResponse

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

--

This problem seems to go away if I do a flush after indexing the data:

client.admin().indices().prepareFlush().execute().actionGet();

Is that necessary?

Thanks,
OGG

On Tuesday, September 11, 2012 1:13:57 PM UTC, Ólafur Gauti Guðmundsson
wrote:

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

--

Necessary if you are performing your search immediatly after your doc insert (unit test).

But, don't do it in production.

Elasticsearch is a "Near Real Time" search engine.

HTH

David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 3 oct. 2012 à 16:39, Ólafur Gauti Guðmundsson oli.gauti@gmail.com a écrit :

This problem seems to go away if I do a flush after indexing the data:

client.admin().indices().prepareFlush().execute().actionGet();

Is that necessary?

Thanks,
OGG

On Tuesday, September 11, 2012 1:13:57 PM UTC, Ólafur Gauti Guðmundsson wrote:
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

--

Its not necessary. Might be you need to refresh, but with "get" there isn't a need to do that as well. Can you possibly gist a simple test cast of this happening? One more question, do you have special mapping for tag_ids, marking it as stored perhaps?

On Oct 3, 2012, at 10:39 AM, Ólafur Gauti Guðmundsson oli.gauti@gmail.com wrote:

This problem seems to go away if I do a flush after indexing the data:

client.admin().indices().prepareFlush().execute().actionGet();

Is that necessary?

Thanks,
OGG

On Tuesday, September 11, 2012 1:13:57 PM UTC, Ólafur Gauti Guðmundsson wrote:
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

--

--

Ooops. Sorry. I had misread its code. I thought he was searching...

My bad.

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 3 oct. 2012 à 18:38, Shay Banon kimchy@gmail.com a écrit :

Its not necessary. Might be you need to refresh, but with "get" there isn't a need to do that as well. Can you possibly gist a simple test cast of this happening? One more question, do you have special mapping for tag_ids, marking it as stored perhaps?

On Oct 3, 2012, at 10:39 AM, Ólafur Gauti Guðmundsson oli.gauti@gmail.com wrote:

This problem seems to go away if I do a flush after indexing the data:

client.admin().indices().prepareFlush().execute().actionGet();

Is that necessary?

Thanks,
OGG

On Tuesday, September 11, 2012 1:13:57 PM UTC, Ólafur Gauti Guðmundsson wrote:
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

--

--

--

Thanks for the reply!
Yes, the tag_ids field is marked as stored in my mapping:

"tag_ids" : {"store" : "yes", "type":"integer", "index" : "not_analyzed"}

I'll try to create a simple case demonstrating this.

Best regards,
OGG

On Wednesday, October 3, 2012 4:38:17 PM UTC, kimchy wrote:

Its not necessary. Might be you need to refresh, but with "get" there
isn't a need to do that as well. Can you possibly gist a simple test cast
of this happening? One more question, do you have special mapping for
tag_ids, marking it as stored perhaps?

On Oct 3, 2012, at 10:39 AM, Ólafur Gauti Guðmundsson <oli....@gmail.com<javascript:>>
wrote:

This problem seems to go away if I do a flush after indexing the data:

client.admin().indices().prepareFlush().execute().actionGet();

Is that necessary?

Thanks,
OGG

On Tuesday, September 11, 2012 1:13:57 PM UTC, Ólafur Gauti Guðmundsson
wrote:

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

--

--