# Word count score

**URL:** <https://discuss.elastic.co/t/word-count-score/22389>\
**Category:** Elasticsearch\
**Created:** [February 25, 2015, 4:33pm UTC](https://discuss.elastic.co/t/word-count-score/22389 "2015-02-25T16:33:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christophe\_Rosko](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@Christophe\_Rosko](https://discuss.elastic.co/u/Christophe_Rosko)\
**Post date:** [February 25, 2015, 4:33pm UTC](https://discuss.elastic.co/t/word-count-score/22389/1 "2015-02-25T16:33:55Z")

</div>

Hi !

I'd like to calculate the score of a query as the number of matched  
wordsas, as do sphinx's "word\_count".  
For example, if the query is "word1 word2 word3",  
then for each document, if the title contains word1, his score will be 1,  
if it contains word1 and word2 the score will be 2, and the score will be 3  
if it contains the 3 words.

How could I do that ?

Thanks for your help !

--  
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/349babc4-5899-431e-9208-2bd6f9bea30f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/349babc4-5899-431e-9208-2bd6f9bea30f%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Chris\_Pall](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chris_pall/32/861_2.png) [@Chris\_Pall](https://discuss.elastic.co/u/Chris_Pall)\
**Post date:** [February 26, 2015, 3:45am UTC](https://discuss.elastic.co/t/word-count-score/22389/2 "2015-02-26T03:45:51Z")

</div>

You can use multiple terms in a should clause:

[https://www.found.no/play/gist/905a2a067dd79593e8f5](https://www.found.no/play/gist/905a2a067dd79593e8f5)

Ignore the comment about stackoverflow in the save, I learned about this  
way to share elasticsearch queries through the example given there. Sorry  
about that.

There may be simpler ways, but this way works pretty effectively.

On Wednesday, February 25, 2015 at 11:33:55 AM UTC-5, Christophe Rosko  
wrote:

> Hi !
> 
> I'd like to calculate the score of a query as the number of matched  
> wordsas, as do sphinx's "word\_count".  
> For example, if the query is "word1 word2 word3",  
> then for each document, if the title contains word1, his score will be 1,  
> if it contains word1 and word2 the score will be 2, and the score will be 3  
> if it contains the 3 words.
> 
> How could I do that ?
> 
> Thanks for your help !

--  
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/5bbd7090-1622-40ec-ab98-50c2925ac555%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5bbd7090-1622-40ec-ab98-50c2925ac555%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Christophe\_Rosko](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@Christophe\_Rosko](https://discuss.elastic.co/u/Christophe_Rosko)\
**Post date:** [February 26, 2015, 9:05am UTC](https://discuss.elastic.co/t/word-count-score/22389/3 "2015-02-26T09:05:42Z")

</div>

Hi Chris,

Thanks for your answer.  
This is not exactly the behaviour I expected.  
What i'd like to have on your example is :  
=\> "Microscopic examination of specimen from bacteria" has a score equals  
to 3 because it's matching 3 words  
=\> "Bacteria specimen" has a score equals to 2 because it's matching 2 words  
=\> etc

How can I adapt your query to get this kind of score ?

Thanks for your help

Le jeudi 26 février 2015 04:45:52 UTC+1, Chris Pall a écrit :

> You can use multiple terms in a should clause:
> 
> [https://www.found.no/play/gist/905a2a067dd79593e8f5](https://www.found.no/play/gist/905a2a067dd79593e8f5)
> 
> Ignore the comment about stackoverflow in the save, I learned about this  
> way to share elasticsearch queries through the example given there. Sorry  
> about that.
> 
> There may be simpler ways, but this way works pretty effectively.
> 
> On Wednesday, February 25, 2015 at 11:33:55 AM UTC-5, Christophe Rosko  
> wrote:
> 
> > Hi !
> > 
> > I'd like to calculate the score of a query as the number of matched  
> > wordsas, as do sphinx's "word\_count".  
> > For example, if the query is "word1 word2 word3",  
> > then for each document, if the title contains word1, his score will be 1,  
> > if it contains word1 and word2 the score will be 2, and the score will be 3  
> > if it contains the 3 words.
> > 
> > How could I do that ?
> > 
> > Thanks for your help !

--  
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/26876144-7f0c-43e6-9576-1cb56aeaeb58%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/26876144-7f0c-43e6-9576-1cb56aeaeb58%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Chris\_Pall](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chris_pall/32/861_2.png) [@Chris\_Pall](https://discuss.elastic.co/u/Chris_Pall)\
**Post date:** [February 26, 2015, 2:03pm UTC](https://discuss.elastic.co/t/word-count-score/22389/4 "2015-02-26T14:03:04Z")

</div>

I'm not exactly sure how to get it to set exactly a particular score. I  
played around with constant\_score for a minute or two but had to move on.

I was hoping that just getting the relevance score correct would suit your  
purposes -- good luck!

On Thu, Feb 26, 2015 at 4:05 AM, Christophe Rosko [christophe@digiteka.com](mailto:christophe@digiteka.com)  
wrote:

> Hi Chris,
> 
> Thanks for your answer.  
> This is not exactly the behaviour I expected.  
> What i'd like to have on your example is :  
> =\> "Microscopic examination of specimen from bacteria" has a score equals  
> to 3 because it's matching 3 words  
> =\> "Bacteria specimen" has a score equals to 2 because it's matching 2  
> words  
> =\> etc
> 
> How can I adapt your query to get this kind of score ?
> 
> Thanks for your help
> 
> Le jeudi 26 février 2015 04:45:52 UTC+1, Chris Pall a écrit :
> 
> > You can use multiple terms in a should clause:
> > 
> > [https://www.found.no/play/gist/905a2a067dd79593e8f5](https://www.found.no/play/gist/905a2a067dd79593e8f5)
> > 
> > Ignore the comment about stackoverflow in the save, I learned about this  
> > way to share elasticsearch queries through the example given there. Sorry  
> > about that.
> > 
> > There may be simpler ways, but this way works pretty effectively.
> > 
> > On Wednesday, February 25, 2015 at 11:33:55 AM UTC-5, Christophe Rosko  
> > wrote:
> > 
> > > Hi !
> > > 
> > > I'd like to calculate the score of a query as the number of matched  
> > > wordsas, as do sphinx's "word\_count".  
> > > For example, if the query is "word1 word2 word3",  
> > > then for each document, if the title contains word1, his score will be  
> > > 1, if it contains word1 and word2 the score will be 2, and the score will  
> > > be 3 if it contains the 3 words.
> > > 
> > > How could I do that ?
> > > 
> > > Thanks for your help !
> > 
> > --  
> > You received this message because you are subscribed to a topic in the  
> > Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit  
> > [https://groups.google.com/d/topic/elasticsearch/DQaDysus0zc/unsubscribe](https://groups.google.com/d/topic/elasticsearch/DQaDysus0zc/unsubscribe).  
> > To unsubscribe from this group and all its topics, 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/26876144-7f0c-43e6-9576-1cb56aeaeb58%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/26876144-7f0c-43e6-9576-1cb56aeaeb58%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/26876144-7f0c-43e6-9576-1cb56aeaeb58%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/26876144-7f0c-43e6-9576-1cb56aeaeb58%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > 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/CAAnL-vDnp-35Op7PAstykha6QO7%3DYmhsR84JmgHV2VCxCYz5Bg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAAnL-vDnp-35Op7PAstykha6QO7%3DYmhsR84JmgHV2VCxCYz5Bg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Christophe\_Rosko](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@Christophe\_Rosko](https://discuss.elastic.co/u/Christophe_Rosko)\
**Post date:** [February 26, 2015, 3:18pm UTC](https://discuss.elastic.co/t/word-count-score/22389/5 "2015-02-26T15:18:55Z")

</div>

Thanks for your help anyway Chris 🙂  
I'll keep trying and let you know if I find a solution.

And if anyone here know how to do that, please share 🙂

Le jeudi 26 février 2015 15:03:30 UTC+1, Chris Pall a écrit :

> I'm not exactly sure how to get it to set exactly a particular score. I  
> played around with constant\_score for a minute or two but had to move on.
> 
> I was hoping that just getting the relevance score correct would suit your  
> purposes -- good luck!
> 
> On Thu, Feb 26, 2015 at 4:05 AM, Christophe Rosko \<[chris...@digiteka.com](mailto:chris...@digiteka.com)  
> \<javascript:\>\> wrote:
> 
> > Hi Chris,
> > 
> > Thanks for your answer.  
> > This is not exactly the behaviour I expected.  
> > What i'd like to have on your example is :  
> > =\> "Microscopic examination of specimen from bacteria" has a score equals  
> > to 3 because it's matching 3 words  
> > =\> "Bacteria specimen" has a score equals to 2 because it's matching 2  
> > words  
> > =\> etc
> > 
> > How can I adapt your query to get this kind of score ?
> > 
> > Thanks for your help
> > 
> > Le jeudi 26 février 2015 04:45:52 UTC+1, Chris Pall a écrit :
> > 
> > > You can use multiple terms in a should clause:
> > > 
> > > [https://www.found.no/play/gist/905a2a067dd79593e8f5](https://www.found.no/play/gist/905a2a067dd79593e8f5)
> > > 
> > > Ignore the comment about stackoverflow in the save, I learned about this  
> > > way to share elasticsearch queries through the example given there. Sorry  
> > > about that.
> > > 
> > > There may be simpler ways, but this way works pretty effectively.
> > > 
> > > On Wednesday, February 25, 2015 at 11:33:55 AM UTC-5, Christophe Rosko  
> > > wrote:
> > > 
> > > > Hi !
> > > > 
> > > > I'd like to calculate the score of a query as the number of matched  
> > > > wordsas, as do sphinx's "word\_count".  
> > > > For example, if the query is "word1 word2 word3",  
> > > > then for each document, if the title contains word1, his score will be  
> > > > 1, if it contains word1 and word2 the score will be 2, and the score will  
> > > > be 3 if it contains the 3 words.
> > > > 
> > > > How could I do that ?
> > > > 
> > > > Thanks for your help !
> > > 
> > > --  
> > > You received this message because you are subscribed to a topic in the  
> > > Google Groups "elasticsearch" group.  
> > > To unsubscribe from this topic, visit  
> > > [https://groups.google.com/d/topic/elasticsearch/DQaDysus0zc/unsubscribe](https://groups.google.com/d/topic/elasticsearch/DQaDysus0zc/unsubscribe).  
> > > To unsubscribe from this group and all its topics, send an email to  
> > > [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/26876144-7f0c-43e6-9576-1cb56aeaeb58%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/26876144-7f0c-43e6-9576-1cb56aeaeb58%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/26876144-7f0c-43e6-9576-1cb56aeaeb58%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/26876144-7f0c-43e6-9576-1cb56aeaeb58%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .  
> > > 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/ea316e70-4ce4-476e-9211-1c1038d687d6%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ea316e70-4ce4-476e-9211-1c1038d687d6%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, 12:29am UTC](https://discuss.elastic.co/t/word-count-score/22389/6 "2017-07-06T00:29:51Z")

</div>


