How can I calculate score using More-like-this in script score

Hi.
I'm writing a query for searching engine.
I want to calculate the score using cosine similarity(between image feature vectors) and tfidf.
So, I used "function_score" to calculate weighted sum of more-like-this score and cosine similarity.
I found that I should use "script_score" inside "functions" when I use function_score.
But I didnt work. Can anybody help me?

This is my code.

script_query = {
    "function_score": {
      "query": {
                    "bool": {
                        "must": [
                            {"match": {"unitCode": unitCode}},
                            {"match": {"problemLevel": problemLevel}}

                        ]
                    }
                },
     
      "functions": [
        {
            "script_score": {
                    "script": {
                        "source": "cosineSimilarity(params.query_vector, 'fvec') + 1.0",
                        "params": {"query_vector": fvec}
                    }
            }
        
        },
        {
            "script_score": {
              "script": { 
                          "source":
                             {"more_like_this" : 
                                  {
                                    "fields" : ["plainText"],
                                    "like" : text,
                                    "min_term_freq" : 0,
                                    "min_doc_freq" : 0,
                                    "minimum_should_match" : "0%"
                                    }
                                }
                        }
                }
        }         
      ],
      "score_mode": "sum",
      "boost_mode": "sum",
      "max_boost": 4,
      "min_score": 3
    }

}

And error :
RequestError: RequestError(400, 'search_phase_execution_exception', 'Failed to compile inline script [{"more_like_this":{"fields":["plainText"],"like":"윤 모네 학급 친구 대상 으로 집 에서 구독 하 신문 종류 조사 하 았 신문 보 친구 신문 보 친구 두 신문 어느 신문 도 구독 하 친구 었 신문 보 친구 한 택하 았 때 그 친구 신문 구독 하 확률 구하","min_term_freq":0,"min_doc_freq":0,"minimum_should_match":"0%"}}] using lang [painless]')

Thanks.

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