Compute Benford's law into Scripted Fields with Painless

Hello everyone,

I would like to compute the Benford's law into elasticsearch from a doc['some_field'].value with a scripted field,
I have try some lucene expression, but it's doesn't work and Expression is deprecated and support will be removed in the next major version so i would like to try with painless.

If you have any idea to compute this i take :slight_smile:

Any tips appreciated.

Thanks!

Expression is deprecated and support will be removed in the next major version

Just to clarify, this is not correct. Expressions are not being removed yet.

I would like to compute the Benford's law into elasticsearch from a doc['some_field'].value

I'm not familiar with Bendford's law or how to calculate it. Can you describe the algorithm? Also, what type of script (eg scoring script, scripted field, scripted metric agg, etc)?

Hello @rjernst thank you for your answer,

The goal to the Benford's law it's to analyse the first digit distribution.

For example, the first digit of:
15435 is 1
56 is 5
and so on

In my elasticsearch indices i have some number fields and i would like to apply this approach.
But actually it's doesn't work :frowning:

Benford’s Distribution Formula

Code exemple in Java

double p = 0.0;
    for( int k = Math.pow(10,position-1); k < Math.pow(10,position); k++ {
        p += Math.log( 1+1.0/(k*10 + digit) );
    }

return p/Math.log(10);

Thank you for your help

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.