# How to filter records that have no related record

**URL:** https://discuss.elastic.co/t/how-to-filter-records-that-have-no-related-record/263240
**Category:** Elasticsearch
**Created:** [February 4, 2021, 12:57pm UTC](https://discuss.elastic.co/t/how-to-filter-records-that-have-no-related-record/263240 "2021-02-04T12:57:06Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Henk21](https://avatars.discourse-cdn.com/v4/letter/h/e9bcb4/32.png) [@Henk21](https://discuss.elastic.co/u/Henk21)
#### Post date: [February 4, 2021, 12:57pm UTC](https://discuss.elastic.co/t/how-to-filter-records-that-have-no-related-record/263240/1 "2021-02-04T12:57:06Z")

</div>

I am loading a feed (ISE syslog events) in a given index. There are two types of events: _Authentication_ events and _Start_ events. The two are related through some unique _session\_id_.

It may happen that for some _Authentication_ events I never get the corresponding _Start_ event (due to some recovery/retry mechanism upstream).

I would like to filter the _Authentication_ events that have a related _Start_ event. Something I would write in a traditional SQL model as an 'in' clause: `select xxx from yyy where session_id in (select session_id from yyy where ...)`

The two events _Authentication_ and _Start_ may come in any order, and quite close to one another. I had a look at the `join` feature in index mapping, but as far as I can see, it would require that the order between related events be always the same (e.g. parent first - _Authenticate_ event, then child - _Start_ event) so that the parent reference may be looked up and added to enrich the child record. But since I have no control over the order of events and the time elapsed between related events may be too short for ES indexing, I don't think this can fly.

The only solution I have found so far is to control the order of events (and ES indexing) through some batch re-processing of the feeds. Not quite elegant - and with race conditions, on top of it.

Thanks for helping out

---

<div class="post-metadata">

### Author: ![Brian\_McGue](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brian_mcgue/32/63366_2.png) [@Brian\_McGue](https://discuss.elastic.co/u/Brian_McGue)
#### Post date: [February 4, 2021, 6:11pm UTC](https://discuss.elastic.co/t/how-to-filter-records-that-have-no-related-record/263240/2 "2021-02-04T18:11:13Z")

</div>

Hi @Henk21,

It looks like you are using [elasticsearch](https://www.elastic.co/elasticsearch/) rather than Enterprise Search (which includes App Search and Workplace Search), right? If so, the [Elastic Stack subforum](https://discuss.elastic.co/c/elastic-stack/) would be a better place to ask this question.

Best,  
Brian

---

<div class="post-metadata">

### Author: ![Henk21](https://avatars.discourse-cdn.com/v4/letter/h/e9bcb4/32.png) [@Henk21](https://discuss.elastic.co/u/Henk21)
#### Post date: [February 5, 2021, 7:49am UTC](https://discuss.elastic.co/t/how-to-filter-records-that-have-no-related-record/263240/3 "2021-02-05T07:49:34Z")

</div>

Changed the topic as suggested. Thanks

---

<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: [March 5, 2021, 7:49am UTC](https://discuss.elastic.co/t/how-to-filter-records-that-have-no-related-record/263240/4 "2021-03-05T07:49:46Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
