# Intersection between any documents

**URL:** <https://discuss.elastic.co/t/intersection-between-any-documents/22735>\
**Category:** Elasticsearch\
**Created:** [March 18, 2015, 1:34pm UTC](https://discuss.elastic.co/t/intersection-between-any-documents/22735 "2015-03-18T13:34:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phil\_2](https://avatars.discourse-cdn.com/v4/letter/p/ecc23a/32.png) [@Phil\_2](https://discuss.elastic.co/u/Phil_2)\
**Post date:** [March 18, 2015, 1:34pm UTC](https://discuss.elastic.co/t/intersection-between-any-documents/22735/1 "2015-03-18T13:34:37Z")

</div>

I'm trying to wrap my head around this but it may not be possible due to  
the nature of ES.

I have an index of appointments with start time, end time, location and  
participants. I'd like to search for \*any \*appointments that have  
overlapping start and end times at the same location.

I understand that this is in essence a relationship between an index and  
itself and that it is asking ES to query each document against every other  
document.

Is anything like this even possible? Hopefully someone can point me in the  
right direction.

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/a2cd366e-554c-41d5-9134-27a578c778c9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a2cd366e-554c-41d5-9134-27a578c778c9%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [March 18, 2015, 4:42pm UTC](https://discuss.elastic.co/t/intersection-between-any-documents/22735/2 "2015-03-18T16:42:20Z")

</div>

You could do a terms filter on the location along with a range filter query  
for the period you are after.  
That's probably the closest thing.

On 18 March 2015 at 06:34, Phil [philtre.misc@gmail.com](mailto:philtre.misc@gmail.com) wrote:

> I'm trying to wrap my head around this but it may not be possible due to  
> the nature of ES.
> 
> I have an index of appointments with start time, end time, location and  
> participants. I'd like to search for \*any \*appointments that have  
> overlapping start and end times at the same location.
> 
> I understand that this is in essence a relationship between an index and  
> itself and that it is asking ES to query each document against every other  
> document.
> 
> Is anything like this even possible? Hopefully someone can point me in the  
> right direction.
> 
> 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/a2cd366e-554c-41d5-9134-27a578c778c9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a2cd366e-554c-41d5-9134-27a578c778c9%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/a2cd366e-554c-41d5-9134-27a578c778c9%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/a2cd366e-554c-41d5-9134-27a578c778c9%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/CAEYi1X9C-otNrS\_VkW2g7M7FVEvtZv3dpv4rM2u5EC4UaJykAw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAEYi1X9C-otNrS_VkW2g7M7FVEvtZv3dpv4rM2u5EC4UaJykAw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Phil\_2](https://avatars.discourse-cdn.com/v4/letter/p/ecc23a/32.png) [@Phil\_2](https://discuss.elastic.co/u/Phil_2)\
**Post date:** [March 18, 2015, 7:01pm UTC](https://discuss.elastic.co/t/intersection-between-any-documents/22735/3 "2015-03-18T19:01:33Z")

</div>

Unfortunately there is no location/period to filter on. It's looking for  
any date range overlapping with any other date range at the same location.

I'm working on aggregating terms on location, then date histogram time  
"windows" between start and end. Any with doc\_count \> 1 would be  
overlapping.

On Wednesday, 18 March 2015 12:42:49 UTC-4, Mark Walkom wrote:

> You could do a terms filter on the location along with a range filter  
> query for the period you are after.  
> That's probably the closest thing.
> 
> On 18 March 2015 at 06:34, Phil \<[philtr...@gmail.com](mailto:philtr...@gmail.com) \<javascript:\>\> wrote:
> 
> > I'm trying to wrap my head around this but it may not be possible due to  
> > the nature of ES.
> > 
> > I have an index of appointments with start time, end time, location and  
> > participants. I'd like to search for \*any \*appointments that have  
> > overlapping start and end times at the same location.
> > 
> > I understand that this is in essence a relationship between an index and  
> > itself and that it is asking ES to query each document against every other  
> > document.
> > 
> > Is anything like this even possible? Hopefully someone can point me in  
> > the right direction.
> > 
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/a2cd366e-554c-41d5-9134-27a578c778c9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a2cd366e-554c-41d5-9134-27a578c778c9%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/a2cd366e-554c-41d5-9134-27a578c778c9%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/a2cd366e-554c-41d5-9134-27a578c778c9%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/fc78b54f-7034-4a0a-a793-59f39498894e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fc78b54f-7034-4a0a-a793-59f39498894e%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:25am UTC](https://discuss.elastic.co/t/intersection-between-any-documents/22735/4 "2017-07-06T00:25:46Z")

</div>


