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

**URL:** <https://discuss.elastic.co/t/0-19-9-java-api-buggy-behaviour-getting-int-array-from-getresponse/8988>\
**Category:** Elasticsearch\
**Created:** [September 11, 2012, 1:13pm UTC](https://discuss.elastic.co/t/0-19-9-java-api-buggy-behaviour-getting-int-array-from-getresponse/8988 "2012-09-11T13:13:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Olafur\_Gauti\_Gudmund](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/olafur_gauti_gudmund/32/2694_2.png) [@Olafur\_Gauti\_Gudmund](https://discuss.elastic.co/u/Olafur_Gauti_Gudmund)\
**Post date:** [September 11, 2012, 1:13pm UTC](https://discuss.elastic.co/t/0-19-9-java-api-buggy-behaviour-getting-int-array-from-getresponse/8988/1 "2012-09-11T13:13:57Z")

</div>

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

--

---

<div class="post-metadata">

**Author:** ![Olafur\_Gauti\_Gudmund](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/olafur_gauti_gudmund/32/2694_2.png) [@Olafur\_Gauti\_Gudmund](https://discuss.elastic.co/u/Olafur_Gauti_Gudmund)\
**Post date:** [October 3, 2012, 2:39pm UTC](https://discuss.elastic.co/t/0-19-9-java-api-buggy-behaviour-getting-int-array-from-getresponse/8988/2 "2012-10-03T14:39:18Z")

</div>

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

--

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 3, 2012, 3:06pm UTC](https://discuss.elastic.co/t/0-19-9-java-api-buggy-behaviour-getting-int-array-from-getresponse/8988/3 "2012-10-03T15:06:57Z")

</div>

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 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 3 oct. 2012 à 16:39, Ólafur Gauti Guðmundsson [oli.gauti@gmail.com](mailto: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

--

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [October 3, 2012, 4:38pm UTC](https://discuss.elastic.co/t/0-19-9-java-api-buggy-behaviour-getting-int-array-from-getresponse/8988/4 "2012-10-03T16:38:03Z")

</div>

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](mailto: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
> 
> --

--

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 3, 2012, 6:02pm UTC](https://discuss.elastic.co/t/0-19-9-java-api-buggy-behaviour-getting-int-array-from-getresponse/8988/5 "2012-10-03T18:02:43Z")

</div>

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

My bad.

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

Le 3 oct. 2012 à 18:38, Shay Banon [kimchy@gmail.com](mailto: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](mailto: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
> > 
> > --
> 
> --

--

---

<div class="post-metadata">

**Author:** ![Olafur\_Gauti\_Gudmund](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/olafur_gauti_gudmund/32/2694_2.png) [@Olafur\_Gauti\_Gudmund](https://discuss.elastic.co/u/Olafur_Gauti_Gudmund)\
**Post date:** [October 4, 2012, 9:47am UTC](https://discuss.elastic.co/t/0-19-9-java-api-buggy-behaviour-getting-int-array-from-getresponse/8988/6 "2012-10-04T09:47:12Z")

</div>

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](mailto: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
> 
> --

--

---

<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:** [July 6, 2017, 3:10am UTC](https://discuss.elastic.co/t/0-19-9-java-api-buggy-behaviour-getting-int-array-from-getresponse/8988/7 "2017-07-06T03:10:10Z")

</div>


