Elasticsearch functional_score with parameter of type string array as input not working

16 Views Asked by At

I'm using Elasticsearch 8.7.0 and using function_score with some matching rules. Matching part works well when doing non boosted search. When I want to boost based on terms-parameter in my function as shown bellow and when terms-parameter contains more than one item it stops to work ie I get not boosted search result. I'm using a query param "boostedStringArray" sent in and this one should be a string array. Im using:["{boostedStringArray}"] so ES understands it should be string array if I only use [{boostedStringArray}] ES wont allow be to have 0-prepended numbers

What I understand it seems to be something with how "boostedStringArray"-value data is structured due to if I just send one item it works well and document having this "myPropertyToBoostOn"-value is boosted. When I add multiple values function-evaluation does not match terms-expression. My boostedStringArray-query-param looks like bellow when sending one item: boostedStringArray=123 when sending multiple items: boostedStringArray=123%2C234 where 123 and 234 are the values

By this it seems that ES does not do an urldecode for given parameter before putting the value into the boostedStringArray-property. What can I do to fix this, can I use any expression in my query-JSON or is there a better solution to achieve the same "personalized" approach? I know there are query rules in newer ES-versions but cant upgrade

...
"functions": [
    {
        "filter": {
            "terms": {
                "myPropertyToBoostOn": ["{boostedStringArray}"]
            }
        },
        "weight": 3
    }
],
"score_mode": "sum",
"boost_mode": "multiply"
...
0

There are 0 best solutions below