Painless script for the average aggregation based on date difference and one of the date is from params maps

I am trying to calculate the average aggregation based on date difference.
Earlier both the date were in the same index, so tired this for the average index:

        "avg": {
                "script": {
                  "source": "(doc['lastFixed'] - doc['firstFound'])/ (1000*60*60)",
                  "lang": "expression"
                }
              }

but now the I have the 2nd date as HashMap in java and trying to pass that as param. I have around 100 entries in the map with the id and it's date.

Is there any way to iterate the HaspMap in painless script and check the Id of HashMap with the document Id and if they matches then calculate the combined average aggregation for all Ids with their dates.

I am trying with this painless script :

    "for(entry in param.dataset.entrySet())"+
          "{if (item.getKey() == doc['id'])"+
          "{ (doc['lastFixed'] - item.getValue())/ (1000*60*60) }"+
      "}"

But I am not sure will calculate the combined aggregation for all Ids and their dates. as we are not saving or returning anything from the for loop iteration.

Please help me on this

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