Dear team,
I am trying to use dotProduct() in a script sort and failing. The simplified case looks like this:
Setting up the data
PUT test_index
{
"mappings": {
"properties": {
"v": {
"type": "dense_vector",
"dims" : 3
}
}
}
}
POST test_index/_bulk
{ "index" : { "_id" : "1" } }
{"v" : [10, 10, 10]}
{ "index" : { "_id" : "2" } }
{"v" : [10, 20, 30]}
** Searching:**
POST test_index/_search
{
"query" : {
"match_all": {}
},
"sort": [
{
"_script": {
"script": {
"source": "def xt = params.filterVector; return dotProduct(xt,'v')",
"params": {
"filterVector": [10, 10, 10]
}
},
"type": "number"
}
}
]
}
This fails with the following:
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "compile error",
"script_stack": [
"... ams.filterVector; return dotProduct(xt,'v')",
" ^---- HERE"
],
"script": "def xt = params.filterVector; return dotProduct(xt,'v')",
"lang": "painless",
"position": {
"offset": 37,
"start": 12,
"end": 55
}
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "test_index",
"node": "ZbZZiYwFQ1G1mdYgHlSl2w",
"reason": {
"type": "script_exception",
"reason": "compile error",
"script_stack": [
"... ams.filterVector; return dotProduct(xt,'v')",
" ^---- HERE"
],
"script": "def xt = params.filterVector; return dotProduct(xt,'v')",
"lang": "painless",
"position": {
"offset": 37,
"start": 12,
"end": 55
},
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Unknown call [dotProduct] with [2] arguments."
}
}
}
]
},
"status": 400
}
Now, it will work if I rewrite the query like this:
POST test_index/_search
{
"query": {
"script_score" : {
"query" : {"match_all" : {}},
"script": {
"source": """
def xt = params.filterVector;
return dotProduct(xt, 'v');
""",
"params": {
"filterVector": [10, 10, 10]
}
}
}
}
}
This thread made me think that the thing that I am trying to do is already implemented. However, I see that the related PR was never merged with the response We have redesigned vector functions to expect ScoreScript parameter
.
Can you confirm that what I am trying to do is indeed not possible?