# Score based on term frequency only

**URL:** <https://discuss.elastic.co/t/score-based-on-term-frequency-only/15110>\
**Category:** Elasticsearch\
**Created:** [January 5, 2014, 9:57pm UTC](https://discuss.elastic.co/t/score-based-on-term-frequency-only/15110 "2014-01-05T21:57:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevins](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kevins/32/946_2.png) [@kevins](https://discuss.elastic.co/u/kevins)\
**Post date:** [January 5, 2014, 9:57pm UTC](https://discuss.elastic.co/t/score-based-on-term-frequency-only/15110/1 "2014-01-05T21:57:25Z")

</div>

I would like to score based entirely on term count.

For example, given the following two documents:

1. { "apple" }

2. { "apple apple" }

Searching "apple" ranks the first before the second. I wish to rank the  
second, in which the term occurs twice, with a higher score.

Can someone please point me in the right direction for this?

Thank you.

--  
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/1bb386ae-3ab5-4878-9d29-6462eaff14c7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1bb386ae-3ab5-4878-9d29-6462eaff14c7%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [January 6, 2014, 1:13am UTC](https://discuss.elastic.co/t/score-based-on-term-frequency-only/15110/2 "2014-01-06T01:13:50Z")

</div>

You could provide your own Similarity class as a plugin. Don't have any  
sample code in front of me, but it would be based of TFIDFSimilarity and  
you would basically needed to ignore the norms and other values.

[http://lucene.apache.org/core/4\_6\_0/core/org/apache/lucene/search/similarities/TFIDFSimilarity.html](http://lucene.apache.org/core/4_6_0/core/org/apache/lucene/search/similarities/TFIDFSimilarity.html)

The IDF portion could probably remain since it ranks the different terms in  
your query, not the score of each term.

Cheers,

Ivan

On Sun, Jan 5, 2014 at 1:57 PM, Kevin S [kevinsteger@gmail.com](mailto:kevinsteger@gmail.com) wrote:

> I would like to score based entirely on term count.
> 
> For example, given the following two documents:
> 
> 1. { "apple" }
> 
> 2. { "apple apple" }
> 
> Searching "apple" ranks the first before the second. I wish to rank the  
> second, in which the term occurs twice, with a higher score.
> 
> Can someone please point me in the right direction for this?
> 
> Thank you.
> 
> --  
> 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/1bb386ae-3ab5-4878-9d29-6462eaff14c7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1bb386ae-3ab5-4878-9d29-6462eaff14c7%40googlegroups.com)  
> .  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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/CALY%3DcQBwEy7UgdqYQmX3EuO71TwSAMCnDp7hdSkcvxLwH5jMJw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQBwEy7UgdqYQmX3EuO71TwSAMCnDp7hdSkcvxLwH5jMJw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Britta\_Weber](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/britta_weber/32/1113_2.png) [@Britta\_Weber](https://discuss.elastic.co/u/Britta_Weber)\
**Post date:** [January 7, 2014, 4:31pm UTC](https://discuss.elastic.co/t/score-based-on-term-frequency-only/15110/3 "2014-01-07T16:31:29Z")

</div>

You could also use a script as described here:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Cheers,  
Britta

On Mon, Jan 6, 2014 at 2:13 AM, Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com) wrote:

> You could provide your own Similarity class as a plugin. Don't have any  
> sample code in front of me, but it would be based of TFIDFSimilarity and  
> you would basically needed to ignore the norms and other values.
> 
> [TFIDFSimilarity (Lucene 4.6.0 API)](http://lucene.apache.org/core/4_6_0/core/org/apache/lucene/search/similarities/TFIDFSimilarity.html)
> 
> The IDF portion could probably remain since it ranks the different terms in  
> your query, not the score of each term.
> 
> Cheers,
> 
> Ivan
> 
> On Sun, Jan 5, 2014 at 1:57 PM, Kevin S [kevinsteger@gmail.com](mailto:kevinsteger@gmail.com) wrote:
> 
> > I would like to score based entirely on term count.
> > 
> > For example, given the following two documents:
> > 
> > 1. { "apple" }
> > 
> > 2. { "apple apple" }
> > 
> > Searching "apple" ranks the first before the second. I wish to rank the  
> > second, in which the term occurs twice, with a higher score.
> > 
> > Can someone please point me in the right direction for this?
> > 
> > Thank you.
> > 
> > --  
> > 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/1bb386ae-3ab5-4878-9d29-6462eaff14c7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1bb386ae-3ab5-4878-9d29-6462eaff14c7%40googlegroups.com).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> 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/CALY%3DcQBwEy7UgdqYQmX3EuO71TwSAMCnDp7hdSkcvxLwH5jMJw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQBwEy7UgdqYQmX3EuO71TwSAMCnDp7hdSkcvxLwH5jMJw%40mail.gmail.com).
> 
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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/CALhJbBiFtgJOfhBqXkS-%2B2YWnDy81j7c5jaSFEkG%3DVizqTpykg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALhJbBiFtgJOfhBqXkS-%2B2YWnDy81j7c5jaSFEkG%3DVizqTpykg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [January 7, 2014, 5:26pm UTC](https://discuss.elastic.co/t/score-based-on-term-frequency-only/15110/4 "2014-01-07T17:26:31Z")

</div>

Great feature. However, it looks like it is only available in the master  
branch: [Add support for using payloads to boost terms · Issue #3772 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/3772)

--  
Ivan

On Tue, Jan 7, 2014 at 8:31 AM, Britta Weber \<[britta.weber@elasticsearch.com](mailto:britta.weber@elasticsearch.com)

> wrote:

> You could also use a script as described here:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-advanced-scripting.html)
> 
> Cheers,  
> Britta
> 
> On Mon, Jan 6, 2014 at 2:13 AM, Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com) wrote:
> 
> > You could provide your own Similarity class as a plugin. Don't have any  
> > sample code in front of me, but it would be based of TFIDFSimilarity and  
> > you would basically needed to ignore the norms and other values.
> 
> [TFIDFSimilarity (Lucene 4.6.0 API)](http://lucene.apache.org/core/4_6_0/core/org/apache/lucene/search/similarities/TFIDFSimilarity.html)
> 
> > The IDF portion could probably remain since it ranks the different terms  
> > in  
> > your query, not the score of each term.
> > 
> > Cheers,
> > 
> > Ivan
> > 
> > On Sun, Jan 5, 2014 at 1:57 PM, Kevin S [kevinsteger@gmail.com](mailto:kevinsteger@gmail.com) wrote:
> > 
> > > I would like to score based entirely on term count.
> > > 
> > > For example, given the following two documents:
> > > 
> > > 1. { "apple" }
> > > 
> > > 2. { "apple apple" }
> > > 
> > > Searching "apple" ranks the first before the second. I wish to rank the  
> > > second, in which the term occurs twice, with a higher score.
> > > 
> > > Can someone please point me in the right direction for this?
> > > 
> > > Thank you.
> > > 
> > > --  
> > > 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/1bb386ae-3ab5-4878-9d29-6462eaff14c7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1bb386ae-3ab5-4878-9d29-6462eaff14c7%40googlegroups.com)  
> .
> 
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > --  
> > 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/CALY%3DcQBwEy7UgdqYQmX3EuO71TwSAMCnDp7hdSkcvxLwH5jMJw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQBwEy7UgdqYQmX3EuO71TwSAMCnDp7hdSkcvxLwH5jMJw%40mail.gmail.com)  
> .
> 
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> 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/CALhJbBiFtgJOfhBqXkS-%2B2YWnDy81j7c5jaSFEkG%3DVizqTpykg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALhJbBiFtgJOfhBqXkS-%2B2YWnDy81j7c5jaSFEkG%3DVizqTpykg%40mail.gmail.com)  
> .  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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/CALY%3DcQDAzNoZwdcquTqyB70Kpw4DSPSPZr2fe%3DCUbMORv1pbUQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQDAzNoZwdcquTqyB70Kpw4DSPSPZr2fe%3DCUbMORv1pbUQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![David\_Zweigenhaft](https://avatars.discourse-cdn.com/v4/letter/d/ce73a5/32.png) [@David\_Zweigenhaft](https://discuss.elastic.co/u/David_Zweigenhaft)\
**Post date:** [April 21, 2014, 7:14am UTC](https://discuss.elastic.co/t/score-based-on-term-frequency-only/15110/5 "2014-04-21T07:14:40Z")

</div>

I am new in Elasticsearch and I would like to score based entirely on term  
count. I would like to know how you solved it.

Can you provide me your solution ?

Actually, I would like to _count how many times a phrase repeats in a  
document_ (for example the phrase- "apple apple"). Do you think it is  
possible to use the term frequency for phrases counting ?.

I'm really stuck with this and need help.

Thanks you.

On Sunday, January 5, 2014 11:57:25 PM UTC+2, Kevin S wrote:

> I would like to score based entirely on term count.
> 
> For example, given the following two documents:
> 
> 1. { "apple" }
> 
> 2. { "apple apple" }
> 
> Searching "apple" ranks the first before the second. I wish to rank the  
> second, in which the term occurs twice, with a higher score.
> 
> Can someone please point me in the right direction for this?
> 
> Thank you.

--  
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/f4d40f0e-c25e-4c22-9c48-af23eb8794f4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f4d40f0e-c25e-4c22-9c48-af23eb8794f4%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:34am UTC](https://discuss.elastic.co/t/score-based-on-term-frequency-only/15110/6 "2017-07-06T01:34:44Z")

</div>


