# Pearson Correlation & Spearman Correlation

**URL:** <https://discuss.elastic.co/t/pearson-correlation-spearman-correlation/277984>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [July 6, 2021, 4:33pm UTC](https://discuss.elastic.co/t/pearson-correlation-spearman-correlation/277984 "2021-07-06T16:33:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ahmed\_Elsheikh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ahmed_elsheikh/32/91250_2.png) [@Ahmed\_Elsheikh](https://discuss.elastic.co/u/Ahmed_Elsheikh)\
**Post date:** [July 6, 2021, 4:33pm UTC](https://discuss.elastic.co/t/pearson-correlation-spearman-correlation/277984/1 "2021-07-06T16:33:32Z")

</div>

Hello, I am new to ElasticSearch  
I am following [this tutorial](https://www.elastic.co/blog/text-similarity-search-with-vectors-in-elasticsearch) trying to implement Semantic Textual Similarity between a query and set of questions/documents in the Stackoverflow dataset.  
I found that Pearson/Spearman correlation are not pre-implemented in painless functions of ES,

1. How can I implement them in a custom query script? I am looking for guidance and/or code snippets
2. How can I sort the results `desc`? or are they sorted `desc` by default, I noticed they were already sorted `desc`
3. This is a general STS question, why most of the research paper showing their results in Pearson & Spearman Correlation, sometimes Cosine Similarity, while most of the online tutorials/materials have scores reported in Cosine Similarity? Does this mean for STS cosine similarity is better than the others?

---

<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:** [August 3, 2021, 4:34pm UTC](https://discuss.elastic.co/t/pearson-correlation-spearman-correlation/277984/2 "2021-08-03T16:34:16Z")

</div>

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