Solr field stats
Field-Stats in Solr can be used to return several statistics.
http://localhost:8983/solr/collection1/
select?q=*:*&
wt=json&
fl=id,cat,manu,price&
indent=true&
omitHeader=true&
rows=2&
stats=true&
stats.field=price
{
"response":{
"numFound":1035,"start":0,
"docs":[
{
"id":"GB18030TEST",
"price":0.0},
{
"id":"SP2514N",
"manu":"Samsung Electronics Co. Ltd.",
"cat":["electronics", "hard drive"],
"price":92.0}
]
},
"stats":{
"stats_fields":{
"price":{
"min":0.0,
"max":2199.0,
"count":1019,
"missing":16,
"sum":9811.870031356812,
"sumOfSquares":6068541.435907734,
"mean":9.628920541076361,
"stddev":76.60569132919564,
"facets":{}
}
}
}
}
Stats can be split into multiple groups
By using stats.facet , stats can be further split into different groups.
http://localhost:8983/solr/collection1/
select?q=*:*&
wt=json&
fl=id,cat,manu,price&
indent=true&
omitHeader=true&
rows=2&
stats=true&
stats.field=price&
stats.facet=inStock
{
"response":{
"numFound":1035,"start":0,
"docs":[
{
"id":"GB18030TEST",
"price":0.0},
{
"id":"SP2514N",
"manu":"Samsung Electronics Co. Ltd.",
"cat":["electronics",
"hard drive"],
"price":92.0}
]
},
"stats":{
"stats_fields":{
"price":{
"min":0.0,
"max":2199.0,
"count":1019,
"missing":16,
"sum":9811.870031356812,
"sumOfSquares":6068541.435907734,
"mean":9.628920541076361,
"stddev":76.60569132919564,
"facets":{
"inStock":{
"":{
"min":0.0,
"max":30.0,
"count":1003,
"missing":11,
"sum":4560.60000038147,
"sumOfSquares":29922.26000770569,
"mean":4.546959123012432,
"stddev":3.0277159875652053,
"facets":{}},
"false":{
"min":11.5,
"max":649.989990234375,
"count":4,
"missing":0,
"sum":1161.3900032043457,
"sumOfSquares":653369.2541528536,
"mean":290.3475008010864,
"stddev":324.63444532124953,
"facets":{}
},
"true":{
"min":0.0,
"max":2199.0,
"count":12,
"missing":5,
"sum":4089.880027770996,
"sumOfSquares":5385249.921747174,
"mean":340.823335647583,
"stddev":602.3683083752779,
"facets":{}
}
}
}
}
}
}
}
Note that the sum of stats from each facet equals the facet count of the total.
Example:
1019 = 1003 + 4 + 12
(count) = (count:facet:"") + (count:facet:"false") + (count:facet:"true")
Same is true of any other stat like
2199.0 = max ( 30.0, 649.989990234375, 2199.0 )
(max) = max (max:facet:"", max:facet:"false", max:facet:"true")