Scripted field to find percent of documents to be used in a metric

I made a scripted field in Kibana using the below which syntactically is fine but doesn't function properly.
I want to take the amount of documents with "Execution", divide that hit count by 10, then multiply that number by 100 to get a percent.

if (doc.containsKey('Execution') ) {
    return Integer.parseInt(doc['tactic.keyword'].sum / 10 * 100)
}

When using scripted fields from kibana, the scripts only have access to document level data.

However, you might find this helpful - https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-scripted-metric-aggregation.html

Excellent, thanks Matthew

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