# Cosine Similarity ElasticSearch

**URL:** <https://discuss.elastic.co/t/cosine-similarity-elasticsearch/18897>\
**Category:** Elasticsearch\
**Created:** [July 25, 2014, 9:28am UTC](https://discuss.elastic.co/t/cosine-similarity-elasticsearch/18897 "2014-07-25T09:28:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![RickDast](https://avatars.discourse-cdn.com/v4/letter/r/8797f3/32.png) [@RickDast](https://discuss.elastic.co/u/RickDast)\
**Post date:** [July 25, 2014, 9:28am UTC](https://discuss.elastic.co/t/cosine-similarity-elasticsearch/18897/1 "2014-07-25T09:28:01Z")

</div>

Hi,

I'm using elasticsearch to index documents and then, with an other document, I score similarity using the "more\_like\_this" query.  
Just two questions:

Does the "more\_like\_this" query use cosine similarity to score documents (I've read the documentation, but I'm still not sure)?  
There is a way to get the scores between 0 and 1?

Thanks!

---

<div class="post-metadata">

**Author:** ![peter\_SP](https://avatars.discourse-cdn.com/v4/letter/p/bbce88/32.png) [@peter\_SP](https://discuss.elastic.co/u/peter_SP)\
**Post date:** [July 30, 2014, 11:46am UTC](https://discuss.elastic.co/t/cosine-similarity-elasticsearch/18897/2 "2014-07-30T11:46:03Z")

</div>

I am also interested in this question.

I have found a fairly old code snippet [1] to calculate the cosine  
similarity in lucene, but I was wondering if elasticsearch provided an  
easier API to access this information.

[1]

> **[Computing Document Similarity using Lucene Term Vectors](http://sujitpal.blogspot.com/2011/10/computing-document-similarity-using.html)**
>
> Someone asked me a question recently about implementing document similarity, and since he was using Lucene, I pointed him to the Lucene Term...

Hi,

> I'm using elasticsearch to index documents and then, with an other  
> document,  
> I score similarity using the "more\_like\_this" query.  
> Just two questions:
> 
> Does the "more\_like\_this" query use cosine similarity to score documents  
> (I've read the documentation, but I'm still not sure)?  
> There is a way to get the scores between 0 and 1?
> 
> Thanks!
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Cosine-Similarity-ElasticSearch-tp4060620.html](http://elasticsearch-users.115913.n3.nabble.com/Cosine-Similarity-ElasticSearch-tp4060620.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/6a2e446d-ec13-4db6-8cff-651ab5108235%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6a2e446d-ec13-4db6-8cff-651ab5108235%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![RickDast](https://avatars.discourse-cdn.com/v4/letter/r/8797f3/32.png) [@RickDast](https://discuss.elastic.co/u/RickDast)\
**Post date:** [August 1, 2014, 8:41am UTC](https://discuss.elastic.co/t/cosine-similarity-elasticsearch/18897/3 "2014-08-01T08:41:42Z")

</div>

There is someone that can help us?

Thank you very much!

---

<div class="post-metadata">

**Author:** ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)\
**Post date:** [August 1, 2014, 9:04am UTC](https://discuss.elastic.co/t/cosine-similarity-elasticsearch/18897/4 "2014-08-01T09:04:30Z")

</div>

Hello Rick ,

MLT query translates the source document into a normal boolean terms query.  
This query is fired against the index and a normal TF IDF is used to find  
the score.  
AFAIK this is the working of MLT.

Thanks  
Vineeth

On Fri, Aug 1, 2014 at 2:11 PM, RickDast [chiccobia@gmail.com](mailto:chiccobia@gmail.com) wrote:

> There is someone that can help us?
> 
> Thank you very much!
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Cosine-Similarity-ElasticSearch-tp4060620p4061039.html](http://elasticsearch-users.115913.n3.nabble.com/Cosine-Similarity-ElasticSearch-tp4060620p4061039.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/1406882502942-4061039.post%40n3.nabble.com](https://groups.google.com/d/msgid/elasticsearch/1406882502942-4061039.post%40n3.nabble.com)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAGdPd5n\_Gk7AiDFywUnb-AQ5e-Z2k6GCCvORGBS8SN2Htj9hdg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5n_Gk7AiDFywUnb-AQ5e-Z2k6GCCvORGBS8SN2Htj9hdg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Alex\_S\_V](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alex_s_v/32/1317_2.png) [@Alex\_S\_V](https://discuss.elastic.co/u/Alex_S_V)\
**Post date:** [August 1, 2014, 12:07pm UTC](https://discuss.elastic.co/t/cosine-similarity-elasticsearch/18897/5 "2014-08-01T12:07:39Z")

</div>

Hi,

I found some native script codings from Igor Motov  
here: [https://github.com/imotov/elasticsearch-native-script-example/blob/master/src/main/java/org/elasticsearch/examples/nativescript/script/CosineSimilarityScoreScript.java](https://github.com/imotov/elasticsearch-native-script-example/blob/master/src/main/java/org/elasticsearch/examples/nativescript/script/CosineSimilarityScoreScript.java)

and now playing with it

Alex

On Friday, August 1, 2014 11:53:24 AM UTC+3, Federico Bianchi wrote:

> There is someone that can help us?
> 
> Thank you very much!
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Cosine-Similarity-ElasticSearch-tp4060620p4061039.html](http://elasticsearch-users.115913.n3.nabble.com/Cosine-Similarity-ElasticSearch-tp4060620p4061039.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/5b9025dd-0173-4b09-ae09-31a2f78e99d7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5b9025dd-0173-4b09-ae09-31a2f78e99d7%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [July 6, 2017, 1:11am UTC](https://discuss.elastic.co/t/cosine-similarity-elasticsearch/18897/6 "2017-07-06T01:11:42Z")

</div>


