Failed shards resulting inconsistent result when using 3 nodes wighted avg with script

Hey,

I encounter a problem using aggregation for weighted avg with a script, this problem accrued when I use 3 nodes architecture when using 1 or 2 nodes is worked properly

I will try to give more specific use case for you to undesrtand my problem ,
because the error could be a bit diffrent according to the index configuration (the amount of shard it has) , but basically it the same error.
I executed my query on index assets_data_test2020_1_7 witch currently contains only 1 shard and 1 replica
I attached the query I executed in the attachments as “query”
and also attached the “good results” and “bad results” , I want to clarify I executed the same query and its randomly getting the “good results” and the “bad results” and it seems that the reason for that is that it’s using different node.

I also attached the error logs for the time stamp: 2020-04-10T05:45

It does not matter whether I use the simplest search “query” once I use the script inside the weighted avg :

POST /exams/_search
{
“size”: 0,
“aggs” : {
“weighted_grade”: {
“weighted_avg”: {
“value”: {
“script”: “100”
},
“weight”: {
“script”: “100”
}
}
}
}
}

the good results is : the calcuated query and hits,
the bad results is : {
“error”: {
“root_cause”: [
{
“type”: “null_pointer_exception”,
“reason”: null
}
],
“type”: “search_phase_execution_exception”,
“reason”: “all shards failed”,
“phase”: “query”,
“grouped”: true,
“failed_shards”: [
{
“shard”: 0,
“index”: “assets_data_test2020_1_7”,
“node”: “E2FfvQ5FTjqrB0wCsnh4Qw”,
“reason”: {
“type”: “null_pointer_exception”,
“reason”: null
}
}
],
“caused_by”: {
“type”: “null_pointer_exception”,
“reason”: null,
“caused_by”: {
“type”: “null_pointer_exception”,
“reason”: null
}
}
},
“status”: 500
}

the error becomes more complex once I use more than 1 shards, but basically the problem is that one of the servers failed on specific shards(or all)

Let me know if you need more info regarding this error