# Similarity score in array

**URL:** <https://discuss.elastic.co/t/similarity-score-in-array/13714>\
**Category:** Elasticsearch\
**Created:** [September 22, 2013, 5:56pm UTC](https://discuss.elastic.co/t/similarity-score-in-array/13714 "2013-09-22T17:56:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ban\_Mido](https://avatars.discourse-cdn.com/v4/letter/b/dec6dc/32.png) [@Ban\_Mido](https://discuss.elastic.co/u/Ban_Mido)\
**Post date:** [September 22, 2013, 5:56pm UTC](https://discuss.elastic.co/t/similarity-score-in-array/13714/1 "2013-09-22T17:56:35Z")

</div>

Hi ,

I have a field called tags which is an array of elements and i have applied  
a flat analyzer over it.  
Now i want a array of tags and i want to see which feed matches the array  
of tags the most. The logic to similarity is that

1. The feed with maximum number of matching tags should come first.
2. In case if 2 feeds have same amount of matched tag , then the feed  
with the highest percentage of matched tag should come.

In short if my query is "terms" : { "tags" : ["one" , "two"] } ,  
then the feed { "tags" : ["one" , "two" , "three" , "four"]} should have  
greater similarity score over the feed { "tags" : [ "one" , "two" , "three"  
, "four" , "five" ] because for the latter feed the percentage of matched  
tags is 75% and for former percentage of matched tags is 60%.

Thanks  
Vineeth

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![ppearcy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppearcy/32/980_2.png) [@ppearcy](https://discuss.elastic.co/u/ppearcy)\
**Post date:** [September 24, 2013, 2:56am UTC](https://discuss.elastic.co/t/similarity-score-in-array/13714/2 "2013-09-24T02:56:35Z")

</div>

Hi,  
Doing a stock sort on score will get you most of the way there. However,  
it will not strictly adhere to the first rule since it is TF/IDF based.

Implementing a custom score would definitely work:

> **[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.

Getting more out there, but likely more optimal, you could perhaps define  
your own similarity model. Something to play around with at least:

> **[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.

Best Regards,  
Paul

On Sunday, September 22, 2013 1:56:35 PM UTC-4, Ban Mido wrote:

> Hi ,
> 
> I have a field called tags which is an array of elements and i have  
> applied a flat analyzer over it.  
> Now i want a array of tags and i want to see which feed matches the array  
> of tags the most. The logic to similarity is that
> 
> 1. The feed with maximum number of matching tags should come first.
> 2. In case if 2 feeds have same amount of matched tag , then the feed  
> with the highest percentage of matched tag should come.
> 
> In short if my query is "terms" : { "tags" : ["one" , "two"] } ,  
> then the feed { "tags" : ["one" , "two" , "three" , "four"]} should have  
> greater similarity score over the feed { "tags" : [ "one" , "two" , "three"  
> , "four" , "five" ] because for the latter feed the percentage of matched  
> tags is 75% and for former percentage of matched tags is 60%.
> 
> Thanks  
> Vineeth

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:15am UTC](https://discuss.elastic.co/t/similarity-score-in-array/13714/3 "2017-07-06T02:15:00Z")

</div>


