Search API - Problem creating a Document with a java.lang.Double Field

65 views
Skip to first unread message

Rafael Martony

unread,
Mar 12, 2015, 6:39:09 PM3/12/15
to google-a...@googlegroups.com
Hi, my application is being developed in Java using Search API.
I'm having trouble storing a double value when creating a new Document and in App Engine Logs appears

Uncaught exception from servlet
java
.lang.IllegalArgumentException: number value, 3638255040.000000, must be less than or equal to 2147483647.000000
 at com
.google.appengine.api.search.checkers.Preconditions.checkArgument(Preconditions.java:54)
 at com
.google.appengine.api.search.checkers.FieldChecker.checkNumber(FieldChecker.java:137)
 at com
.google.appengine.api.search.Field$Builder.setNumber(Field.java:136)
 at com
.appspot.comprasestatalesuy.server.service.DocumentService.preCreateDocumentBuilder(DocumentService.java:604)
 at com
.appspot.comprasestatalesuy.server.service.DocumentService.createDocument(DocumentService.java:127)

I'm creating a Document like this

...
Document.Builder docBuilder = Document.newBuilder().addField(Field.newBuilder().setName("monto_adj").setNumber(adjudicacion.getMonto())); // Monto is a double
...
Document document = docBuilder.build();



Isn't 3638255040.000000 a valid double number?

Your help would be greatly appreciated!

Vinny P

unread,
Mar 13, 2015, 1:08:34 AM3/13/15
to google-a...@googlegroups.com
On Thu, Mar 12, 2015 at 5:31 PM, Rafael Martony <rmar...@gmail.com> wrote:
Hi, my application is being developed in Java using Search API.
I'm having trouble storing a double value when creating a new Document and in App Engine Logs appears
 


You are correct in saying that your number fits into a Java double primitive, but it exceeds the Search API's  maximum number value.

 

-----------------
-Vinny P
Technology & Media Consultant
Chicago, IL

App Engine Code Samples: http://www.learntogoogleit.com



 

Rafael Martony

unread,
Mar 16, 2015, 7:57:27 AM3/16/15
to google-a...@googlegroups.com
Thanks Vinny !
I have to find another solution for storing doubles with Search API.

Nick

unread,
Mar 17, 2015, 5:48:03 AM3/17/15
to google-a...@googlegroups.com
There are a few options within the search api:

Scale/truncate the double to fit - this fails if your double has a wide range (such as very large and very small values across the dataset)

Store in multiple fields and create a query that knows how to span them (ie store the low and high quantities separately, such as everything before the decimal point in one value, shifted down appropriately and everything after the decimal point shifted up).

Stringify the double and store as a string, note that comparisons and ordering will be alphabetical so you'll need to zero pad the start and end, negative numbers would also be an issue.


Outside of that, you'll probably need to find another way, such as cloudsql, the datastore or another external search index (like elastic search on GCE)

As an aside, the search index is not very good with numbers. As you've learnt, it actually has the range of an int, with the precision of a float passed in as a double (wtf?).
It also behaves oddly when doing granular range queries. For example, if you do a query where x <= 0.21, it can in practice return values larger than this, such as 0.22. This seems to be related to how it writes the index, grouping indexed values into 'batches'.

There's also a faceted search api in trusted tester I think, this might be the thing for you.

It would be interesting to hear what you actually choose in the end.

Vinny P

unread,
Mar 18, 2015, 2:05:42 AM3/18/15
to google-a...@googlegroups.com
On Tue, Mar 17, 2015 at 4:48 AM, Nick <naok...@gmail.com> wrote:
Outside of that, you'll probably need to find another way, such as cloudsql, the datastore or another external search index (like elastic search on GCE)


I would emphasize the last option: elastic search on GCE. There's a click to deploy Elasticsearch option in the cloud console ( https://cloud.google.com/solutions/elasticsearch/click-to-deploy ) - it's very simple to deploy and try it out for your use case.
Reply all
Reply to author
Forward
0 new messages