I want to store a histogram in elasticsearch but I'm having trouble finding an example of a way to do this via script. The histogram buckets will be values 0-23, and I need to be able to increment buckets individually via script, and keep track of which bucket has the highest value after each update.
If I were going to store this myself I could use a hashmap with 24 different keys, but given Elasticsearch already has a histogram type, my assumption is it would be better to use that.
There is a
Histrogram interface and
InternalHistogram class in the java documentation, but trying to instantiate an
InternalHistogram, use a builder method, or use a
HistogramFactory, results in an error stating that type doesn't exist.
How can I achieve something like this?:
ctx._source.histogram.put('my_histogram', InternalHistogram.create([0, 1, 2 ... 23])); ctx._source.histogram.get('my_histogram') .values = ctx._source.histogram.get('my_histogram').values + 1;