# How is the score of Significant Term aggregation calculated?

**URL:** https://discuss.elastic.co/t/how-is-the-score-of-significant-term-aggregation-calculated/141329
**Category:** Elasticsearch
**Created:** [July 24, 2018, 8:44am UTC](https://discuss.elastic.co/t/how-is-the-score-of-significant-term-aggregation-calculated/141329 "2018-07-24T08:44:20Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![ahrtr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ahrtr/32/29551_2.png) [@ahrtr](https://discuss.elastic.co/u/ahrtr)
#### Post date: [July 24, 2018, 8:44am UTC](https://discuss.elastic.co/t/how-is-the-score-of-significant-term-aggregation-calculated/141329/1 "2018-07-24T08:44:21Z")

</div>

It's a little confusing how is the score of Significant Term aggregation calculated. Another thing is about the criteria of highlighting significant items. I know that a term is considered significant if there is a noticeable difference in the frequency in which a term appears in the subset and in the background, but it's unclear on the criteria of the "noticeable difference".

Can anybody please clarify these questions? Thanks.

---

<div class="post-metadata">

### Author: ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)
#### Post date: [July 24, 2018, 9:33am UTC](https://discuss.elastic.co/t/how-is-the-score-of-significant-term-aggregation-calculated/141329/2 "2018-07-24T09:33:28Z")

</div>

From [the docs](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-significantterms-aggregation.html#_jlh_score) :

> The scores are derived from the doc frequencies in foreground and background sets. The absolute change in popularity (foregroundPercent - backgroundPercent) would favor common terms whereas the relative change in popularity (foregroundPercent/ backgroundPercent) would favor rare terms. Rare vs common is essentially a precision vs recall balance and so the absolute and relative changes are multiplied to provide a sweet spot between precision and recall.

JLH is the default scoring algo but there are others and they all use the same 4 numbers as input:

- size of foreground set
- frequency of term in foreground set
- size of background set
- frequency of term in background set.

[This video](https://www.youtube.com/watch?v=azP15yvbOBA) provides a visual demo of scores on various queries and the positive effects of sampling.

---

<div class="post-metadata">

### Author: ![ahrtr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ahrtr/32/29551_2.png) [@ahrtr](https://discuss.elastic.co/u/ahrtr)
#### Post date: [July 24, 2018, 11:54pm UTC](https://discuss.elastic.co/t/how-is-the-score-of-significant-term-aggregation-calculated/141329/3 "2018-07-24T23:54:07Z")

</div>

@Mark_Harwood Thanks for the info.

So the score = (foregroundPercent - backgroundPercent) \* (foregroundPercent/ backgroundPercent), correct?

Is the foregroundPercent always greater than the backgroundPercent in this case?

---

<div class="post-metadata">

### Author: ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)
#### Post date: [July 25, 2018, 8:05am UTC](https://discuss.elastic.co/t/how-is-the-score-of-significant-term-aggregation-calculated/141329/4 "2018-07-25T08:05:25Z")

</div>

> [@ahrtr](#):
>
> Is the foregroundPercent always greater than the backgroundPercent in this case?

For the JLH score, yes. Positive correlations generally tend to be the ones people want rather than negative correlations....

> "like this product? Then here's some others you'll hate...."

If you want the negative correlations try the [mutual information](https://www.elastic.co/guide/en/elasticsearch/reference/master/search-aggregations-bucket-significantterms-aggregation.html#_mutual_information) heuristic.

---

<div class="post-metadata">

### Author: ![ahrtr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ahrtr/32/29551_2.png) [@ahrtr](https://discuss.elastic.co/u/ahrtr)
#### Post date: [July 25, 2018, 8:17am UTC](https://discuss.elastic.co/t/how-is-the-score-of-significant-term-aggregation-calculated/141329/5 "2018-07-25T08:17:03Z")

</div>

Thank you !

---

<div class="post-metadata">

### Author: ![mind\_scratch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mind_scratch/32/34507_2.png) [@mind\_scratch](https://discuss.elastic.co/u/mind_scratch)
#### Post date: [August 15, 2018, 2:00pm UTC](https://discuss.elastic.co/t/how-is-the-score-of-significant-term-aggregation-calculated/141329/6 "2018-08-15T14:00:16Z")

</div>

If I have 3 documents in the foreground set, each with the term "hello":  
doc1: hello shows up 2 times  
doc2: hello shows up 1 time  
doc3: hello shows up 4 times

Then "frequency of term in foreground set" would be 7, correct?  
And "size of foreground set" would be 3? (since there are 3 docs? ...or would it be the total number of terms over the 3 docs)?

---

<div class="post-metadata">

### Author: ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)
#### Post date: [August 15, 2018, 2:16pm UTC](https://discuss.elastic.co/t/how-is-the-score-of-significant-term-aggregation-calculated/141329/7 "2018-08-15T14:16:57Z")

</div>

> Then "frequency of term in foreground set" would be 7, correct?

Nope. Doc frequencies are the number of docs that contain the word at least once.

---

<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: [September 12, 2018, 2:17pm UTC](https://discuss.elastic.co/t/how-is-the-score-of-significant-term-aggregation-calculated/141329/8 "2018-09-12T14:17:09Z")

</div>

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