I have a number of docs indexed by Solr 3.5, which contain date fields (solr.DateField) among others. Now I do request to Solr component which should return no results:
http://example.com/solr/select?fq=sis_field_int:1000&
stats=true&stats.field=ds_field_date
and get error
HTTP Status 500 - / by zero java.lang.ArithmeticException: / by zero at
org.apache.solr.handler.component.DateStatsValues.addTypeSpecificStats
(StatsValuesFactory.java:384) at ...
If I send request without stats part or specify any non-date stats field instead, I get expected response with no results. It looks like a bug of Solr which tries e.g. to calculate mean value in this case. Unfortunately I've found no references on this problem. Is there some way to bypass or solve the problem?
You're right, the problem is computing the mean value:
res.add("mean", new Date(sum / count));
sum
and count
are both long
. When count
is zero, of course you get an ArithmeticException
. You're actually making stats on a date field which never has a value in your index. The easiest workaround would be making stats on a field which has at least one value, so the count
variable would be greather than zero, the division will work, and the stats would be even more meaningful I guess.
You don't get the same error with the same situation using a numeric field, because in that case the sum variable is double
, thus the division don't raise error and the result is NaN
. In fact, there are different StatsValues
implementations based on the field type.
UPDATE
I've opened the SOLR-3160 jira issue and provided a patch which has just been committed. The next release of Solr will contain the fix!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With