It works !
Here is the correct snippet:
// construction de la request
request = new SearchTemplateRequest();
request.setRequest(searchRequest);
request.setScriptType(ScriptType.INLINE);
// " \"source\": \"cosineSimilarity([{{value_vector}}], doc['{{interro_vector}}']) + 1.0\" " +
// " \"source\": \"cosineSimilarity([{{value_vector}}], '" + enrg.getInterrogation() + "') + 1.0\" " +
// " \"source\": \"cosineSimilarity([" + dense_vector + "], doc['" + enrg.getInterrogation() + "']) + 1.0\" " +
script =
"{ \"query\": " +
"{" +
" \"script_score\": { " +
" \"query\": { " +
" \"query_string\" : { " +
" \"query\" : \"" + query + "\", " +
" \"default_field\" : \"tout\" " +
" } " +
" }, " +
" \"script\": { " +
" \"source\": \"cosineSimilarity([" + dense_vector + "], doc['" + enrg.getInterrogation() + "']) + 1.0\" " +
" } " +
" } " +
"}" +
"} ";
request.setScript(script);
Map<String, Object> scriptParams = new HashMap<>();
//scriptParams.put("interro_vector", enrg.getInterrogation());
//scriptParams.put("value_vector", dvalues );
request.setScriptParams(scriptParams);
I believed I tried this before calling for help but you proved me that it was not the case....
Could not make it work with aggregation but I know that you are working hard on full integration.
I was following your work since the day you made this post
It took me several months to fully apprehend the range of your post and be able to use it.
I feel ashamed to post silly questions about bad formed syntax regarding the elegance of the solution you implemented in Elasticsearch and the power it brings by marrying the speed of Elasticsearch and the power of BERT.
The results are simply atonishing ! The dream of semantic search with Elastic comes true !
Thank you Mayya for this wonderful accomplishment !