在没有结果的情况下,Solr StatsComponent 的日期字段除以零错误
我有许多由 Solr 3.5 索引的文档,其中包含日期字段(solr.DateField)等。现在我确实向 Solr 组件发出请求,该组件不应返回任何结果:
http://example.com/solr/select?fq=sis_field_int:1000&
stats=true&stats.field=ds_field_date
并收到错误
HTTP Status 500 - / by zero java.lang.ArithmeticException: / by zero at
org.apache.solr.handler.component.DateStatsValues.addTypeSpecificStats
(StatsValuesFactory.java:384) at ...
如果我发送不带统计信息部分的请求或指定任何非日期统计字段,我会得到没有结果的预期响应。它看起来像 Solr 的一个错误,它尝试在这种情况下计算平均值。不幸的是我没有找到关于这个问题的参考资料。有什么办法可以绕过或者解决这个问题吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你是对的,问题是计算平均值:
sum
和count
都是long
。当count
为零时,您当然会得到一个ArithmeticException
。您实际上是在对索引中从未有值的日期字段进行统计。最简单的解决方法是在至少有一个值的字段上进行统计,因此count
变量将大于零,除法将起作用,并且我认为统计数据将更有意义。使用数字字段在相同的情况下不会出现相同的错误,因为在这种情况下,sum 变量是 double,因此除法不会引发错误,结果是 NaN 。事实上,根据字段类型有不同的 StatsValues 实现。
更新
我已经打开了 SOLR-3160 jira 问题并提供了一个补丁,该补丁刚刚已承诺。 Solr 的下一个版本将包含修复程序!
You're right, the problem is computing the mean value:
sum
andcount
are bothlong
. Whencount
is zero, of course you get anArithmeticException
. 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 thecount
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 isNaN
. In fact, there are differentStatsValues
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!