Hi All,
I am trying to understand the reason as to why ElasticSearch would return me a hit with _score 0 even though my search caused the document to be matched. I also have a custom score function that would not allow 0 as _score unless the original _score is 0.
My query is below:
`{
"size": 250,
"query": {
"function_score": {
"query": {
"bool": {
"should": [
{
"match": {
"title": {
"query": "Amy Schumer",
"type": "phrase_prefix"
}
}
},
{
"match": {
"episodeTitle": {
"query": "Amy Schumer",
"type": "phrase_prefix"
}
}
},
{
"match": {
"actors": {
"query": "Amy Schumer",
"type": "phrase_prefix",
}
}
},
{
"match": {
"directors": {
"query": "Amy Schumer",
"type": "phrase_prefix"
}
}
},
{
"match": {
"genres": {
"query": "Amy Schumer",
"type": "phrase_prefix"
}
}
}
]
}
},
"script_score": {
"script": "_score * (_source.type == 'PEOPLE' ? 30 : 1) * (_source.type == 'SERIES' ? 80 : 1) * (_source.type == 'GENRE' ? 40 : 1) * (_source.type == 'LINEAR' ? _source.distance : 1) * (_source.type == 'MOVIE' ? 2.5 : 1) * (_source.type == 'MOVIE' && _source.newMovie ? 10 : 1)"
}
}
},
"highlight" : {
"order": "score",
"fields" : {
"title" : {"type" : "plain"},
"episodeTitle" : {"type" : "plain"},
"genres" : {"type" : "plain"},
"actors" : {"type" : "plain"},
"directors" : {"type" : "plain"}
}
}
}`
So my function score works pretty much like this: Genres, Actors and Tv Series should get a high score, so if I search for "Amy Schumer", the actor should come first and then the movie Trainwreck, since she was an actor in this movie. if I search for "Drama", the genre Drama comes first and then movies, programs and Tv Series with Drama in the genre. If I search for "Jim Parsons", I would get first the Actor, then the TV Series and everything else that matches my query after.
The problem is that by searching for "Amy Schumer", Trainwreck gets _score ZERO, but it shouldnt since its a new movie, so the original score should be multiplied by 2.5 (because its a movie) and 10 (because its a new movie).
This is the pastebin for my explain result for Trainwreck: http://pastebin.com/Hb9SCFpr . I would post here but only 5000 chars are allowed.
Thank you
Thiago