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

**URL:** https://discuss.elastic.co/t/how-can-i-calculate-score-using-more-like-this-in-script-score/259949
**Category:** Elasticsearch
**Created:** [December 31, 2020, 9:59am UTC](https://discuss.elastic.co/t/how-can-i-calculate-score-using-more-like-this-in-script-score/259949 "2020-12-31T09:59:55Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![111424](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/111424/32/81601_2.png) [@111424](https://discuss.elastic.co/u/111424)
#### Post date: [December 31, 2020, 9:59am UTC](https://discuss.elastic.co/t/how-can-i-calculate-score-using-more-like-this-in-script-score/259949/1 "2020-12-31T09:59:55Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [January 28, 2021, 10:00am UTC](https://discuss.elastic.co/t/how-can-i-calculate-score-using-more-like-this-in-script-score/259949/2 "2021-01-28T10:00:11Z")

</div>

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