I have this mapping for my index:
"my_index": {
"mappings": {
"properties": {
"medias": {
"properties": {
"media_id": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"media_type": {
"type": "long"
},
"variant": {
"properties": {
"height": {
"type": "long"
},
"url": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"width": {
"type": "long"
}
}
},
"view_count": {
"type": "long"
}
}
}
}
And I want to write a script for custom scoring like this:
// "_source": "content",
"query": {
"function_score": {
"functions": [
{
"script_score": {
"script": {
"source": " (doc.medias.size() == 0 || doc.medias.view_count.size() == 0 ? 0 : doc.medias.view_count.value) "
}
}
}
],
"query": {
"match": {
"content": something"
}
},
"score_mode": "multiply"
}
}
}
But I get this error:
"caused_by": {
"type": "illegal_argument_exception",
"reason": "No field found for [medias] in mapping with types []"
}
I guess I'm not accessing the view_count property correctly. How can I do that? And one more thing: the medias field is an array and if the size of the array exceeded 1 I need to get the maximum of the view_counts. How can I do this?