Cosine similarity not working in elastic search

This is my my query :
script_query = {
"function_score": {
"query" : {
"match_all": {}
},
"script_score": {"script": {
"inline": "cosineSimilarity(params.query_vector, doc['title_vector']) + 1.0",
"params": {
"query_vector": query_vector.tolist()
}}

    }
    }
}

and i am getting the following error:

TransportError: TransportError(500, 'search_phase_execution_exception', "failed to run inline script [cosineSimilarity(params.query_vector, doc['title_vector']) + 1.0] using lang [groovy]")

just to add to the above point when i am adding source in place of inline , i am getting the following error:
TransportError: TransportError(500, 'search_phase_execution_exception', 'unexpected field [source]')

Groovy was dropped some time ago for security reasons. I imagine you're overdue an upgrade of elasticsearch version

I have updated and the error has changed : RequestError: RequestError(400, 'search_phase_execution_exception', 'runtime error'). Detailed error : Unknown key for a START_OBJECT in [function_score].

@Divyanshu_Pandey It should be script_score query, not function_score query. Please follow the documentation here.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.