I'm trying to test the new elasticsearch functionality 'word2vec for text similarity'. I use this little example, but I have the following error! I would like to have feedback and tell me where is the error, knowing that I use version 7.3.2 :
######################################################
Mapping
######################################################
PUT /testw2v
{
"mappings":{
"type_1":{
"_all" : {"enabled" : true},
"properties":{
"text":{ "type":"string"},
"text_vector":{"type": "dense_vector",
"dims": 4}
}
}
}
}
######################################################
put data
######################################################
PUT testw2v_1/_doc/1
{
"text" : "A New Jersey guy dedicated to his family, friends, and church, develops unrealistic expectations from watching porn and works to find happiness and intimacy with his potential true love.",
"text_vector" : [0.01,0.23,0.6,0.34]
}
######################################################
GET query
######################################################
GET /testw2v/_search/
{
"size": 1,
"query": {
"script_score": {
"query": {
"match_all": {}
},
"script": {
"source": "cosineSimilarity(params.queryVector, doc['text_vector'])+1.0",
"params": {
"queryVector": [0.01,0.23,0.6,0.34]
}
}
}
}
}
######################################################
ERROR message
######################################################
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"cosineSimilarity(params.queryVector, doc['text_vector'])+1.0",
" ^---- HERE"
],
"script": "cosineSimilarity(params.queryVector, doc['text_vector'])+1.0",
"lang": "painless"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "testw2v_1",
"node": "Lihza6H3RG6oRqwZYY9AAA",
"reason": {
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"cosineSimilarity(params.queryVector, doc['text_vector'])+1.0",
" ^---- HERE"
],
"script": "cosineSimilarity(params.queryVector, doc['text_vector'])+1.0",
"lang": "painless",
"caused_by": {
"type": "class_cast_exception",
"reason": "class org.elasticsearch.index.fielddata.ScriptDocValues$Doubles cannot be cast to class org.elasticsearch.xpack.vectors.query.VectorScriptDocValues$DenseVectorScriptDocValues (org.elasticsearch.index.fielddata.ScriptDocValues$Doubles is in unnamed module of loader 'app'; org.elasticsearch.xpack.vectors.query.VectorScriptDocValues$DenseVectorScriptDocValues is in unnamed module of loader java.net.FactoryURLClassLoader @7a1f8def)"
}
}
}
]
},
"status": 400
}
######################################################
######################################################
######################################################
######################################################
1- In the search query we have to use POST or GET ?
2- in the mapping, I defined "text_vector" as 'dense_vector' with dim=4, so why this error ?