Schema looks like this:
"mappings": {
"_doc": {
"_all": {
"enabled": false
},
"properties": {
"category_boost": {
"type": "nested",
"properties" : {
"category": {
"type": "text",
"index": false
},
"boost": {
"type": "integer",
"index": false
}
}
}
}
}
}
The document in elastic does have data:
"category_boost": [
{
"category": "A",
"boost": 98
},
{
"category": "B",
"boost": 96
},
{
"category": "C",
"boost": 94
},
],
Inside scoring function:
for (int i=0; i<doc['"'category_boost.boost'"'].size(); ++i) { if (doc['"'category_boost.category'"'][i].value.equals(params.category)) { boost = doc['"'category_boost.boost'"'][i].value; } }
Also tried length
to get size of the array, but did help. Since it does not affect results, I tried to divide by size()
and it throws division by zero error, so I conclude the size is 0.
Overall problem: have a map of category->boost which is dynamic and I cannot hardcode into schema. I tried type object
with json object, but it turned out you cannot access those objects in scoring functions, therefore I went with arrays with defined types.