# Comparing arrays

**URL:** <https://discuss.elastic.co/t/comparing-arrays/19925>\
**Category:** Elasticsearch\
**Created:** [September 23, 2014, 2:18am UTC](https://discuss.elastic.co/t/comparing-arrays/19925 "2014-09-23T02:18:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim\_Uckun](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tim_uckun/32/1256_2.png) [@Tim\_Uckun](https://discuss.elastic.co/u/Tim_Uckun)\
**Post date:** [September 23, 2014, 2:18am UTC](https://discuss.elastic.co/t/comparing-arrays/19925/1 "2014-09-23T02:18:24Z")

</div>

I have documents with an array field. The array contains unique elements  
only. In this case the data is strings and but it could be numbers.

I want to search for documents using this array field. Ideally I would like  
to pass in an array and find the "nearest match" meaning documents which  
contain all or most of the elements in the array I passed in.

For example "find me all the documents with the array field similar to  
['this', 'that', 'the other thing']"

Thanks.

--  
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/CAGuHJrM3oasfU1tX-\_VDPB6seDnzwYP32XKeQCKuySGNgLitKg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGuHJrM3oasfU1tX-_VDPB6seDnzwYP32XKeQCKuySGNgLitKg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Tim\_Uckun](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tim_uckun/32/1256_2.png) [@Tim\_Uckun](https://discuss.elastic.co/u/Tim_Uckun)\
**Post date:** [September 25, 2014, 3:49am UTC](https://discuss.elastic.co/t/comparing-arrays/19925/2 "2014-09-25T03:49:16Z")

</div>

On Tuesday, September 23, 2014 2:18:35 PM UTC+12, Tim Uckun wrote:

> I have documents with an array field. The array contains unique elements  
> only. In this case the data is strings and but it could be numbers.
> 
> I want to search for documents using this array field. Ideally I would  
> like to pass in an array and find the "nearest match" meaning documents  
> which contain all or most of the elements in the array I passed in.
> 
> For example "find me all the documents with the array field similar to  
> ['this', 'that', 'the other thing']"

Hey guys I hate to bump myself up but does anybody have any hints on how  
this could be done?

--  
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/0c705855-5684-45c5-902b-e310178f8e1d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0c705855-5684-45c5-902b-e310178f8e1d%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Anne\_Veling](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anne_veling/32/1260_2.png) [@Anne\_Veling](https://discuss.elastic.co/u/Anne_Veling)\
**Post date:** [September 25, 2014, 1:39pm UTC](https://discuss.elastic.co/t/comparing-arrays/19925/3 "2014-09-25T13:39:01Z")

</div>

I suppose you could simply create a "bool" search with "should" clauses on  
all of the values, like

"query": {  
"bool": [  
"should": { "term": {"array": "this"}},  
"should": { "term": {"array": "that"}},  
"should": { "term": {"array": "other"}}  
]  
}

If you want you can use the minimum\_should\_match field too, or use a  
different query type if you want more control over the sorting and  
filtering of the results?

Anne

On Thu, Sep 25, 2014 at 5:49 AM, Tim Uckun [timuckun@gmail.com](mailto:timuckun@gmail.com) wrote:

> On Tuesday, September 23, 2014 2:18:35 PM UTC+12, Tim Uckun wrote:
> 
> > I have documents with an array field. The array contains unique elements  
> > only. In this case the data is strings and but it could be numbers.
> > 
> > I want to search for documents using this array field. Ideally I would  
> > like to pass in an array and find the "nearest match" meaning documents  
> > which contain all or most of the elements in the array I passed in.
> > 
> > For example "find me all the documents with the array field similar to  
> > ['this', 'that', 'the other thing']"
> 
> Hey guys I hate to bump myself up but does anybody have any hints on how  
> this could be done?
> 
> --  
> 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/0c705855-5684-45c5-902b-e310178f8e1d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0c705855-5684-45c5-902b-e310178f8e1d%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/0c705855-5684-45c5-902b-e310178f8e1d%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/0c705855-5684-45c5-902b-e310178f8e1d%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
Anne Veling  
[BeyondTrees.com](http://BeyondTrees.com)  
+31 6 50 969 170  
@anneveling

--  
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/CAAwWRi%2BuaEYEqT2S4PamfVYRZLAgRoOuSfav6Z0Lqz6Nj40%3DXg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAAwWRi%2BuaEYEqT2S4PamfVYRZLAgRoOuSfav6Z0Lqz6Nj40%3DXg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)\
**Post date:** [September 25, 2014, 1:55pm UTC](https://discuss.elastic.co/t/comparing-arrays/19925/4 "2014-09-25T13:55:09Z")

</div>

Hello Tim ,

The default similarity already have this logic in it , but then am sure  
there are other logics too applied for default similarity.  
I am not sure how to use this function logic alone for scoring.

But then , in worst case you can do as follows , but am sure there should  
exist and better way for thos.  
Create a script in scoring and use the ( score =  
\_index['FIELD']['TERM'].tf() \> 0 ? 1 : 0 ) and sum all the score for each  
term as the score of that document. -

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

Thanks  
vineeth

On Thu, Sep 25, 2014 at 9:19 AM, Tim Uckun [timuckun@gmail.com](mailto:timuckun@gmail.com) wrote:

> On Tuesday, September 23, 2014 2:18:35 PM UTC+12, Tim Uckun wrote:
> 
> > I have documents with an array field. The array contains unique elements  
> > only. In this case the data is strings and but it could be numbers.
> > 
> > I want to search for documents using this array field. Ideally I would  
> > like to pass in an array and find the "nearest match" meaning documents  
> > which contain all or most of the elements in the array I passed in.
> > 
> > For example "find me all the documents with the array field similar to  
> > ['this', 'that', 'the other thing']"
> 
> Hey guys I hate to bump myself up but does anybody have any hints on how  
> this could be done?
> 
> --  
> 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/0c705855-5684-45c5-902b-e310178f8e1d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0c705855-5684-45c5-902b-e310178f8e1d%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/0c705855-5684-45c5-902b-e310178f8e1d%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/0c705855-5684-45c5-902b-e310178f8e1d%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/CAGdPd5mgz7hVRC8VjJyhpEm8QLk%3DSJYr96sS-zrQe%2Bqy1UqX%2BQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5mgz7hVRC8VjJyhpEm8QLk%3DSJYr96sS-zrQe%2Bqy1UqX%2BQ%40mail.gmail.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:59am UTC](https://discuss.elastic.co/t/comparing-arrays/19925/5 "2017-07-06T00:59:58Z")

</div>


