I am newbie and this is my first attempt. I have few documents with this json
{
"_index": "msm",
"_type": "bat",
"_id": "AWBP0tthO9VGNRQOwYSB",
"_version": 1,
"_score": 1,
"_source": {
"testMethodsSummary": {
"passed": 5,
"failed": 1,
"skipped": 0
}
}
}
These documents are dynamic and keep coming every min. I have to iterate over all documents and do the sum of passed, failed and skipped - calculate the total and do the % of pass.
I tried this and the total is calculated for each document - but I want the total for all documents for different types and index's. Any help would really appreciate.
GET msm/_search
{
"query": {
"match": {"_type":"bat"}
},
"script_fields": {
"total": {
"script": {
"lang": "painless",
"source": "int total = 0; for (int i = 0; i < doc['testMethodsSummary.passed'].length; ++i) { total += doc['testMethodsSummary.passed'][i]+doc['testMethodsSummary.failed'][i]+doc['testMethodsSummary.skipped'][i]; } return total;"
}
}
}
}