Allow faceting on decimal fields
I'd like to create a facet on a Price field stored as a decimal in my MongoDB documents. However, this doesn't give me the results I expect. I'm required to set the "boundaries" property on the facet to an array of integer or double values. However, when the facets are returned, they are all thrown into the "default" bucket.
For example, if I were to declare the facet like this:
facets: {
price: {
type: "number",
path: "ProductPrice",
// using plain integer boundaries 0,10,20,30 also fails
boundaries: [ 0, 5.00, 10.00, 15.00, 20.00, 25.00, 30.00 ],
default: "other",
},
},
I incorrectly get results like this:
"facet" : {
"price" : {
"buckets" : [
{
"_id" : 0.0,
"count" : NumberLong(0)
},
{
"_id" : 5.0,
"count" : NumberLong(0)
},
{
"_id" : 10.0,
"count" : NumberLong(0)
},
{
"_id" : 15.0,
"count" : NumberLong(0)
},
{
"_id" : 20.0,
"count" : NumberLong(0)
},
{
"_id" : 25.0,
"count" : NumberLong(0)
},
{
"_id" : "other",
"count" : NumberLong(1304)
}
]
}
}
Instead of having my results distributed across my price ranges.
8
votes
