Reputation: 21
I am using a painless script to implement a custom scoring function while querying the ES index, that's being used as a basis for our recommendation engine. While calculating the final score in the painless script, I use a product of intermediate variables such as recency and uniqueness, calculated within the painless script.
Now, it is trivial to get the final scores of the top documents as they are returned within the query response. However, for detailed analysis, I'm trying to find a way to also get the intermediate variables' values (recency and uniqueness as in the above example). I understand these painless variables only exist within the context of the painless script, which does not have standard REPL setup. So is there really no way to access these painless variables? Has anyone found a workaround to do this? Thanks!
E.g. If I have the following simplified painless script:
def recency = 1/doc['date'].value
def uniqueness = doc['ctr].value
return recency * uniqueness
In the final ES response, I get the scores i.e. recency * uniqueness
. However, I also want to know what the intermediate variables are i.e. recency
and uniqueness
Upvotes: 1
Views: 9429
Reputation: 1
There is not direct way of printing it anywhere i suppose. But here is what you can give it a try to check the intermediate output of any variable.
For Ex: in your case,
"script_fields": {
"derivedRecency": {
"script": {
"lang": "painless",
"source": """
return doc['recency'].value;
"""
}
}
}
Upvotes: 0
Reputation: 61
You can try using a modular approach with multiple scripted fields like:
uniqueness -- get the uniqueness field
access the fields like a normal ES field in your final painless script
if(doc.containsKey('recency.keyword') && doc.containsKey('uniqueness.keyword'))
{
def val1 = doc['recency.keyword'].value;
def val2 = doc['uniqueness.keyword'].value;
}
Hope it helps
Upvotes: 1