Consider the following output:
Anomaly on Sep 16 @ 11:45 PM:
Partner: p1 Brand: b1
Score=94.71 Actual=15 Typical=744.49
How do I go about adding more partners or brands, instead of getting this:
Anomaly on Sep 16 @ 11:45 PM:
Partner: {0=p1, 1=p2} Brand: {0=b1, 1=b2}
Score=94.71 Actual=15 Typical=744.49
And End up with this:
== Anomaly on Sep 16 @ 11:45 PM: ==
Partner: p1, p2 Brand: b1, b2
Score=94.71 Actual=15 Typical=744.49
I can get the following:
partner=
p._source.influencers[0]['influencer_field_values'].0
or
brand=
p._source.influencers[1]['influencer_field_values'].0
if I actually specify it, but not all have more than 1, so how do I loop:
p._source.influencers[..]['influencer_field_values']
to display either:
[..]['influencer_field_values'].0
[..]['influencer_field_values'].1
[..]['influencer_field_values'].2
?
( where .. is either [0] or [1] depending on if I am trying to get partner or brand. The end (.0 or .1 or .2 ) is the part Im trying to figure out how to iterate.
Here is what I have to transform the output I have now:
"transform": {
"script": {
"source": "def df = new DecimalFormat('##.##'); return [ 'anomaly_details':ctx.payload.hits.hits.stream().map(p -> ['start_time':Instant.ofEpochMilli(p._source.timestamp).atZone(ZoneId.systemDefault()).minus(Duration.ofMinutes(20)).format(DateTimeFormatter.ofPattern('MMM d @ h:mm a')),'end_time':Instant.ofEpochMilli(p._source.timestamp).atZone(ZoneId.systemDefault()).plus(Duration.ofMinutes(20)).format(DateTimeFormatter.ofPattern('MMM d @ h:mm a')),'bucket_time':Instant.ofEpochMilli(p._source.timestamp).atZone(ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern('MMM d @ h:mm a')),'job_id':p._source.job_id,'score':df.format(p._source.record_score),'actual':df.format(p._source.actual.0),'typical':df.format(p._source.typical.0),'partner':p._source.influencers[0]['influencer_field_values'].0,'brand':p._source.influencers[1]['influencer_field_values'].0,'start_time_iso_instant':Instant.ofEpochMilli(p._source.timestamp).atZone(ZoneId.systemDefault()).minus(Duration.ofMinutes(20)).format(DateTimeFormatter.ISO_INSTANT),'end_time_iso_instant':Instant.ofEpochMilli(p._source.timestamp).atZone(ZoneId.systemDefault()).plus(Duration.ofMinutes(20)).format(DateTimeFormatter.ISO_INSTANT) ]).collect(Collectors.toList())]",
"lang": "painless"
}