Hi, I have a document with a nested array, and I'm trying to get a nested value in a funtion score but I can't (I always get 0).
For example having the following mapping:
{
"mapping":{
"movie":{
"properties":{
"title":{ "type":"string" },
"reviews":{
"type":"nested",
"properties":{
"rating":{ "type":"long" },
"userId":{ "type":"string", "index":"not_analyzed" }
}
}
}
}
}
}
I want to set the score with the rating of a particular user. To do that I execute this query:
{
"query" : {
"function_score" : {
"functions" : [ {
"filter" : {
"nested" : {
"filter" : { "term" : { "userId" : "1" } },
"path" : "reviews"
}
},
"script_score" : {
"script" : "doc['reviews.rating'].value"
}
} ]
}
}
}
But that query returns _score = 0 for all records.
Is there a way to score based on a nested value?
(I'm using a function score instead of a nested sorting because I have several score functions and I took the max)
Thanks, Claudio.
Here there are some example documents:
{
"title": "The Godfather",
"reviews": [
{ "userId": "1", "rating": "5" },
{ "userId": "2", "rating": "4" }
]
}
{
"title": "Rocky",
"reviews": [
{ "userId": "1", "rating": "3" },
{ "userId": "2", "rating": "5" }
]
}