Hello,
I have an issue with this painless script file in (/etc/elasticsearch/scripts) to create an entity centric index :
//------------------------------------------------------- ----------------------------------------------------------
def docSrc = ctx._source;
def codeStatusSuccess_1 = "200";
def iOS = "1";
def Android = "2";
def Web = "3";
//------------------------------------------------------- ----------------------------------------------------------
if("create".equals(ctx.op)){
//initialize entity state
docSrc.Field1 = [];
}
//------------------------------------------------------- ----------------------------------------------------------
def req1Map =[:];
for (req1 in docSrc.Field1) {
req1Map[req1.id]=req1;
}
//------------------------------------------------------- ----------------------------------------------------------
for (event in params.events) {
def req1 =req1Map[event.id];
if(req1 ==null){
req1=[
"id": event.id,
"login": event.login,
"statusCode": event.statusCode,
"media": event.media,
"createdAt": event.created_at,
"countEvent": 1
];
req1Map[req1.id]=req1;
}else{
req1.countEvent ++;
}
}
//------------------------------------------------------- ----------------------------------------------------------
docSrc.Field1 = req1Map.values();
//------------------------------------------------------- ----------------------------------------------------------
def nbAllReq = 0;
def login;
def totalReq = 0;
def nbAndroidSuccessReq = 0;
def nbAndroidErrorsReq = 0;
def nbWebSuccessReq = 0;
def nbWebErrorsReq = 0;
def nbiOSSuccessReq = 0;
def nbiOSErrorsReq = 0;
def nbUnknownSuccessReq = 0;
def nbUnknownErrosReq = 0;
for (req1 in docSrc.Field1){
nbAllReq += req1.countEvent;
login = req1.login;
}
for (req1 in docSrc.Field1){
if (req1.media == Android && req1.statusCode == codeStatusSuccess_1){
nbAndroidSuccessReq += req1.countEvent;
**FirstAnrdoidSuccessIDreq** =
**LastAndroidSuccessIDreq** =
**DateFirstAndroidSuccessReq** =
**DateLastAnrdoidSuccessReq** =
}
else if (req1.media == Android && req1.statusCode){
nbAndroidErrorsReq += req1.countEvent;
**FirstAndroidFailedIDreq** =
**LastAndroidFailedIDreq** =
**DateFirstAndroidFailedReq** =
**DateLastAnrdoidFailedReq** =
}
else if (req1.media == Web && req1.statusCode == codeStatusSuccess_1){
nbWebSuccessReq += req1.countEvent;
**FirstWebSuccessIDreq** =
**LastWebSuccessIDreq** =
**DateFirstWebSuccessReq** =
**DateLastWebSuccessReq** =
}
else if (req1.media == Web && req1.statusCode != codeStatusSuccess_1){
nbWebErrorsReq += req1.countEvent;
**FirstWebFailedIDreq** =
**LastWebFailedIDreq** =
**DateFirstWebFailedReq** =
**DateLastWebFailedReq** =
}
else if (req1.media == iOS && req1.statusCode == codeStatusSuccess_1){
nbiOSSuccessReq += req1.countEvent;
**FirstiOSSuccessIDreq** =
**LastiOSSuccessIDreq** =
**DateFirstiOSSuccessReq** =
**DateLastiOSSuccessReq** =
}
else if (req1.media == iOS && req1.statusCode != codeStatusSuccess_1){
nbiOSErrorsReq += req1.countEvent;
**FirstiOSFailedIDreq** =
**LastiOSFailedIDreq** =
**DateFirstiOSFailedReq** =
**DateLastiOSFailedReq** =
}
else if ((req1.media != iOS || req1.media != Android || req1.media != Web) && (req1.statusCode == codeStatusSuccess_1)){
nbUnknownSuccessReq += req1.countEvent;
**FirstUnknownSuccessIDreq** =
**LastUnknownSuccessIDreq** =
**DateFirstUnknownSuccessReq** =
**DateLastUnknownSuccessReq** =
}
else{
nbUnknownErrosReq += req1.countEvent;
**FirstUnknownFailedIDreq** =
**LastUnknownFailedIDreq** =
**DateFirstUnknownFailedReq** =
**DateLastUnknownFailedReq** =
}
}
//------------------------------------------------------- ----------------------------------------------------------
docSrc.nbAllReq = nbAllReq;
docSrc.login = login;
docSrc.nbAndroidSuccessReq = (int)nbAndroidSuccessReq;
docSrc.nbAndroidErrorsReq = (int)nbAndroidErrorsReq;
docSrc.nbWebSuccessReq = (int)nbWebSuccessReq;
docSrc.nbWebErrorsReq = (int)nbWebErrorsReq;
docSrc.nbiOSSuccessReq = (int)nbiOSSuccessReq;
docSrc.nbiOSErrorsReq = (int)nbiOSErrorsReq;
docSrc.nbUnknownSuccessReq = (int)nbUnknownSuccessReq;
docSrc.nbUnknownErrosReq = (int)nbUnknownErrosReq;
I would like to get in every loop the Max, Min created_at field (date) and Max,Min id field (int).
(How to use Max, Min, Unique Count ... functions for integer and date values).
Could you please give me a good reference or doc on painless language for elasticsearch?
Example of output :
"nbUnknownErrosReq": 0, "nbAllReq": 101, "nbiOSErrorsReq": 0, "nbAndroidErrorsReq": 0, "nbWebErrorsReq": 1, "nbWebSuccessReq": 100, "nbUnknownSuccessReq": 0, "nbAndroidSuccessReq": 0, "FirstWebSuccessIDreq" : 101 "LastWebSuccessIDreq" : 200 "DateFirstWebSuccessReq" : "2017-07-01T12:20:30" "DateLastWebSuccessReq" : "2017-07-10T23:11:34" "FirstWebFailedIDreq" : 122 "LastWebFailedIDreq" : 122 "DateFirstWebFailedReq" : "2017-07-6T8:32:12" "DateLastWebFailedReq" : "2017-07-6T8:32:12"
Thank you in advance