Round the values returned by facets


(Yehuda Zargarov) #1

Is it possible to perform a query which returns floating values
rounded by x places after the points?


(Igor Motov) #2

It's possible to modify the value of the fields you are calculating facets
on using term scripts
(http://www.elasticsearch.org/guide/reference/api/search/facets/terms-facet.html)

For example, the following query will return facets with floating values in
the my_field field rounded by 2 decimal places.

{
"size" : 0,
"query" : { "query_string" : {"query" : ":"} },
"facets" : {
"from" : {
"terms" : {
"field" : "my_field",
"script": "round(term*100)/100"
}
}
}
}

Igor Motov

On Monday, March 12, 2012 9:48:23 AM UTC-4, Yehuda Zargarov wrote:

Is it possible to perform a query which returns floating values
rounded by x places after the points?


(system) #3