I log an "event" field that contains various String values. I want to find the number of occurrences of a specific value "button clicked" and then multiply it by a monetary amount to calculate revenue and show this as a Metric visual.
Eg number of occurrences of event:"button clicked" * 0.25
One way you could do this is with a scripted field. That field might be clickValueInUSD, which has a field formatter for currency and a script value like doc['event'].values.includes('button clicked') ? 0.25 : 0 and then create a metric aggregation on the sum of that field.
I tried adding this scripted field exactly as you provided. Please see the attached screenshot.
When I run a metric 'sum' visual on this scripted field, Kibana complains with:
Error: Request to Elasticsearch failed: {"error":{"root_cause":[{"type":"script_exception","reason":"Failed to parse expression: doc['event'].values.includes('button clicked') ? (0.25) : 0"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"logstash-2016.05.21","node":"y35NyWVvSMy_bDDwfUVj7w","reason":{"type":"script_exception","reason":"Failed to compile inline script [doc['event'].values.includes('button clicked') ? (0.25) : 0] using lang [expression]","caused_by":{"type":"script_exception","reason":"Failed to parse expression: doc['event'].values.includes('button clicked') ? (0.25) : 0","caused_by":{"type":"parse_exception","reason":"unexpected character ''' on line (1) position (29)","caused_by":{"type":"lexer_no_viable_alt_exception","reason":null}}}}}]}}
Googling this hasn't revealed any solution other than to ask what scripting language is this? Do I need to enable something in Kibana to allow this script to run?
Hi @warkolm, I read the link you provided and allegedly enabled scripting by adding to my /etc/elasticsearch/elasticsearch.yml:
script.inline: true
script.indexed: true
I restarted my ES server. I deleted/re-added my script but I still get the same parse error as I reported above when adding my Metric visual. How can I know that scripting is enabled in the elasticsearch logs?
Hi @warkolm, can you be more specific about how to enable scripting since the link you provided didn't help. Is there a specific language I need to enable as well? When I restart ES, should the logs say that scripting for a given language is enabled?
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.