I ran into an issue where script_score was dropping documents from my results. In the end I narrowed it down to the field not yet existing in my mapping and I solved it by explictly adding the priority field to my mapping.
The query below returns no documents at all if I have only documents without the priority field.
{
"query": {
"filtered": {
"query": {
"function_score": {
"query": {
"match_all": {}
},
"score_mode": "max",
"functions": [
{
"script_score": {
"script": "doc['priority'].value;"
}
}
]
}
},
"filter": {
"and": [
{
"ids": {
"values": [
"A",
"B",
"C"
]
}
}
]
}
}
}
}
In any case, this behavior seems weird. I would expect script_score to never drop documents and merely do something to the score. Instead, it seems to actually drop all documents because the field does not exist in the mapping. As soon as the field mapping exists, the query works as expected.
I was wondering whether to report this as a bug or whether there is some good reason for this somewhat counter intuitive behavior.