I have discovered that from Elasticsearch version 5, "python language plugin" is deprecated in favor of the new default scripting language "Painless". Source: https://www.elastic.co/guide/en/elasticsearch/plugins/current/lang-python.html
Could anybody help me converting these 2 python scripts (hot ranking scripts from hacker news & reddit taken from this blog https://medium.com/hacking-and-gonzo/how-reddit-ranking-algorithms-work-ef111e33d0d9#.10tv859uq) to Painless?
Script 1 (hacker news)
def calculate_score(votes, item_hour_age, gravity=1.8): return (votes - 1) / pow((item_hour_age+2), gravity)
Script 2 (reddit)
from datetime import datetime, timedelta from math import log epoch = datetime(1970, 1, 1) def epoch_seconds(date): td = date - epoch return td.days * 86400 + td.seconds + (float(td.microseconds) / 1000000) def score(ups, downs): return ups - downs def hot(ups, downs, date): s = score(ups, downs) order = log(max(abs(s), 1), 10) sign = 1 if s > 0 else -1 if s < 0 else 0 seconds = epoch_seconds(date) - 1134028003 return round(sign * order + seconds / 45000, 7)
I think this could be useful for a lot of people trying to understand the new "Painless" scripting language.
P.S. I am no expert in scripting or Python.