new DateTime().getMillis; from = to - 24時間前; sum = 0; for (i=0; i<fav_array.length; i++) { if (from < time_array[i] && time_array[i] < to) sum += fav_array[i]; } return sum; { "fuction_score":{ "query":{ "term”: { “category":”ゲーム” }, "functions":{ "script_score":{ "script":"fav_array=doc['fav_array']. values; ... " } } } } }