# Computing intesecting sets on searches

**URL:** <https://discuss.elastic.co/t/computing-intesecting-sets-on-searches/13333>\
**Category:** Elasticsearch\
**Created:** [August 26, 2013, 7:43pm UTC](https://discuss.elastic.co/t/computing-intesecting-sets-on-searches/13333 "2013-08-26T19:43:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fernand\_Galiana](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fernand_galiana/32/2143_2.png) [@Fernand\_Galiana](https://discuss.elastic.co/u/Fernand_Galiana)\
**Post date:** [August 26, 2013, 7:43pm UTC](https://discuss.elastic.co/t/computing-intesecting-sets-on-searches/13333/1 "2013-08-26T19:43:39Z")

</div>

Hi,

I have indexed documents with tags and want to be able to fetch  
documents that match a query given the following constraint...

Say doc1 has tags [a,b] and during a query I would like to compute an  
intersection given an ad hoc tags array  
in the form off [a,b] & [a,b,c] = [a,b] ie compute the intersection  
between the 2 sets and check that it returns the original document tag set.

I've been looking a script filters but seems that mvel does not support  
an operator/function to intersect array types.

Any suggestions?

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

---

<div class="post-metadata">

**Author:** ![Boaz\_Leskes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/boaz_leskes/32/723_2.png) [@Boaz\_Leskes](https://discuss.elastic.co/u/Boaz_Leskes)\
**Post date:** [August 27, 2013, 7:42am UTC](https://discuss.elastic.co/t/computing-intesecting-sets-on-searches/13333/2 "2013-08-27T07:42:50Z")

</div>

Hi Fernand,

Mvel gives you access to all Java classes so you can instantiate sets from  
the arrays and do your thing.

How important is performance for you? If this is more than just a quick  
test, I will use combination of scoring and filters to figure out whether  
you have the right number of hits. In your example, search for "a" OR "b"  
with using filters and constant score (or  
potentially [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/custom-filters-score-query/)  
) and then filter using a script filter all document whose score doesn't  
equal to the number of elements in their tag array.

Cheers,  
Boaz

On Monday, August 26, 2013 9:43:39 PM UTC+2, Fernand Galiana wrote:

> Hi,
> 
> I have indexed documents with tags and want to be able to fetch  
> documents that match a query given the following constraint...
> 
> Say doc1 has tags [a,b] and during a query I would like to compute an  
> intersection given an ad hoc tags array  
> in the form off [a,b] & [a,b,c] = [a,b] ie compute the intersection  
> between the 2 sets and check that it returns the original document tag set.
> 
> I've been looking a script filters but seems that mvel does not support  
> an operator/function to intersect array types.
> 
> Any suggestions?
> 
> 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).  
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:19am UTC](https://discuss.elastic.co/t/computing-intesecting-sets-on-searches/13333/3 "2017-07-06T02:19:38Z")

</div>


