How to properly display prices in Kibana

Hello,

I'm trying to properly display prices in Kibaba.

Currently, prices are mapped as a long integer so that 120.00 is stored as 12000. We have some dashboards we show to clients such as their total revenue. I need to display these properly as 120.00.

I've seen that it's recommended to store prices as floating points scaled to 100. However, the lead developer doesn't want to do this as he fears floating points sometimes don't convert properly. For example, he says converting 10000 cents into dollars could yield 99.99999999997.

Any advice on getting this working would be most appreciated. Thanks in advance.

1 Like

You should be able to display them formatted properly by creating a scripted field with the following painless script.

return (doc['total_quantity'].value / 100.0);

You can also change the formatting to $0,0.00.

Thanks for the reply.

Because many documents don't have a value for "price", I got an error. I used an IF statement to fix this and when I preview the scripted field, I get the correct result.

    if (doc['price'].size() > 0) { 
        return doc['price'].value / 100.00;
    }    

I understand using a scripted field uses more resources as the script runs every time a search is made or visualization refreshed. Is there any way to optimize this or reduce server load?

The best way would be to format the data the way you want prior or during ingest, but it sounds like your developer doesn't want to.

If you are ingesting data through Logstash you can do all this in a Logstash filter.

The scripted field works great but I'm experiencing a problem.

I added the scripted filed to filebeat-* However, periodically it simply disappears and I need to recreate the scripted field manually.

Any ideas about how to make this stop?

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