Unable to access doc['field'].value in script_score


#1

I am trying to modify the score of my search results based on the value of two fields, namely "alexaRank" & "pubDate". I get the following error:

"caused_by" : {
"type" : "missing_property_exception",
"reason" : "No such property: alexaRank for class: e5df54b64e7bd114a1f095ce63f339741dcb4f23"
}

The query looks like the following:

curl -XPOST 'localhost:9200/news_cluster/_search?pretty' -d '{
"explain": true, "query":{ "function_score" : {
"query" : {
"multi_match" : {
"query" : "News",
"fields" : [ "title", "url", "description", "content^3" ],
"type" : "phrase",
"slop" : 10,
"tie_breaker" : 0.3
}
},
"functions" : [ {
"gauss" : {
"pubDate" : {
"scale" : "1d",
"decay" : 0.7
}
}
} ,
{
"script_score" : { "params": {"constant": 100.0, "power": 0.25, "defaultRank": 10000.0} , "script":
"rank= doc['alexaRank'].value; score=(constant + defaultRank - rank)**power; return score;",
"lang": "groovy" }} ],
"score_mode" : "multiply",
"boost_mode" : "multiply",
"boost" : 2.0
}
}}'

The index mapping is as below:

"mapping_cluster" : {
"mappings" : {
"articles" : {
"properties" : {
"alexaRank" : {
"type" : "long"
},
"content" : {
"type" : "string"
},
"description" : {
"type" : "string"
},
"imageURL" : {
"type" : "string"
},
"pubDate" : {
"type" : "date",
"format" : "strict_date_optional_time||epoch_millis"
},
"sourceName" : {
"type" : "string"
},
"title" : {
"type" : "string"
},
"url" : {
"type" : "string"
}
}
}
}
}

Was wondering if somebody could help me figure out what the possible issue is? and how i could access the field to modify its score if this is not the right way.
I was thinking of using Function Score Query for this purpose initially, but don't know how i can use it to evaluate using the formula i am using currently (with the allowed modifiers).

Thanks!


#2

Hi.

Resolved. The quotes were not being escaped.
changing doc['alexaRank'] to doc[' " ' "alexaRank" ' " '] solved the problem.


(system) #3

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