histogramelasticsearchfaceted-searchfacet

How to set the number of intervals in an elasticsearch histogram


Using elasticsearch, I'd like to get a histogram facet for a price field in my model. Without knowing beforehand the min and max prices, what I'd like is to have the histogram cover the entire range of prices, with a set number of intervals, say 10. I can see from the documentation at

http://www.elasticsearch.org/guide/reference/api/search/facets/histogram-facet.html

that I can specify the price range for each interval, but this would give me some unspecified number of intervals. I'd like to have some specific number of intervals that evenly cover the entire range of values for the price field. Is there any way to do this?

I know that one solution could be to query my database for the min and max values, and then figure out the appropriate interval size, but that goes against one of the main points of using elasticsearch, which is to not have to hit the db for search related queries.


Solution

  • You can query elasticsearch for min and max values using Statistical Facet