Skip to content

elasticfence/kibana-scripted-metric

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

kibana-scripted-metric

Kibana 4.5 plugin/patch to add support for Scripted Metric Aggregation

{
    "query" : {
        "match_all" : {}
    },
    "aggs": {
        "profit": {
            "scripted_metric": {
                "init_script" : "_agg['transactions'] = []",
                "map_script" : "if (doc['type'].value == \"sale\") { _agg.transactions.add(doc['amount'].value) } else { _agg.transactions.add(-1 * doc['amount'].value) }", 
                "combine_script" : "profit = 0; for (t in _agg.transactions) { profit += t }; return profit",
                "reduce_script" : "profit = 0; for (a in _aggs) { profit += a }; return profit"
            }
        }
    }
}

Status

  • Experimental and Brutal - Use at your OWN risk!

Installation

Backup First!

tar cvfz /opt/kibana/src/ui-backup.tgz -C /opt/kibana/src/ui .
Install Patch
curl -O https://github.com/elasticfence/kibana-scripted-metric/files/441369/kibana-scripted-metric-4.5.0.tar.gz
tar zxvf ./kibana-scripted-metric-4.5.0.tar.gz -C /opt/kibana/src/ui/
rm -rf /opt/kibana/optimize/bundles
Build & Install Patch
cd /usr/src && git clone https://github.com/elasticfence/kibana-scripted-metric
cd kibana-scripted-metric && npm install && npm run package
tar zxvf ./kibana-scripted-metric-4.5.0.tar.gz -C /opt/kibana/src/ui/
rm -rf /opt/kibana/optimize/bundles
Remove / Restore
tar zxvf /opt/kibana/src/ui-backup.tgz -C /opt/kibana/src/ui
rm -rf /opt/kibana/optimize/bundles

Credit

Based on discussion and code related to this thread: elastic/kibana#2646 and patches from https://github.com/fabiangebert/kibana

License

MIT

About

Kibana Scripted Metric AggType [Patch/Plugin] 🔎

Resources

License

Stars

Watchers

Forks

Packages

No packages published