Solr - Get the sum of all “filemetadata.filesize” field for a given user

妖精的绣舞 提交于 2019-12-25 04:57:13

问题


I'm building some kind of file storage software. The files metadata are indexed with fields like filesize and userId The

What I'd like to do is to be able to compute the space used by an user.

For exemple if I have documents:

  • documentId = 1 | userId = 1 | fileSize = 10
  • documentId = 2 | userId = 2 | fileSize = 5
  • documentId = 3 | userId = 1 | fileSize = 3

I'd like to run a query so that for userId=1 I retrieve a result being 13MB (10+3)


I have seen that we can run FunctionQuery but it doesn't seem to do what I'm looking for.

Same for the FieldCollapsing which doesn't permit to run aggregation functions on the grouped results.


I have tested the StatsComponent as well but it doesn't seem to work for unknown reasons.

My schema contains:

<field name="FileSize" type="integer" indexed="false" stored="true" required="true" />
<field name="OtherField" type="sfloat" indexed="true" stored="true" required="false" />
<field name="OtherField2" type="integer" indexed="true" stored="true" required="false" multiValued="false"/>
<field name="OtherField3" type="integer" indexed="true" stored="true" required="false" multiValued="false"/>

And when I perform the query

http://mysolr:8414/solr/mycore/select/?q=docId:123
&rows=0
&stats=true
&stats.field=FileSize
&stats.field=OtherField
&stats.field=OtherField2
&stats.field=OtherField3

I get back the result:

<lst name="stats">
  <lst name="stats_fields">
    <null name="FileSize"/>
    <lst name="OtherField">
      <double name="min">6.0</double>
      <double name="max">6.0</double>
      <long name="count">1</long>
      <long name="missing">0</long>
      <double name="sum">6.0</double>
      <double name="sumOfSquares">36.0</double>
      <double name="mean">6.0</double>
      <double name="stddev">0.0</double>
      <lst name="facets"/>
    </lst>
    <lst name="OtherField2">
      <double name="min">0.0</double>
      <double name="max">0.0</double>
      <long name="count">1</long>
      <long name="missing">0</long>
      <double name="sum">0.0</double>
      <double name="sumOfSquares">0.0</double>
      <double name="mean">0.0</double>
      <double name="stddev">0.0</double>
      <lst name="facets"/>
    </lst>
    <null name="OtherField3"/>
  </lst>
</lst>

As you can see I'm asking for stats for a single doc (which isn't really useful but helps to debug, anyway without the q=docId:123 it doesn't return me a better result). This document has a set FileSize of 15 I use Solr 4.1

Can someone please explain me why I can get stats for fields OtherField and OtherField2, but not for fields FileSize and OtherField3? I don't see the problem at all...


回答1:


Good news, writing this question helped me find the solution. I use a legacy schema and didn't notice that the FileSize field had indexed="false". Passing this attribute to true makes the StatsComponent returns stats for that field!

However, for the field OtherField3 which has exactly the same definition as OtherField2, I have no answer



来源:https://stackoverflow.com/questions/14955165/solr-get-the-sum-of-all-filemetadata-filesize-field-for-a-given-user

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!