# Help with my Query :)

**URL:** <https://discuss.elastic.co/t/help-with-my-query/351975>\
**Category:** Kibana\
**Created:** [January 29, 2024, 9:57am UTC](https://discuss.elastic.co/t/help-with-my-query/351975 "2024-01-29T09:57:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kiwisaki](https://avatars.discourse-cdn.com/v4/letter/k/dfb087/32.png) [@Kiwisaki](https://discuss.elastic.co/u/Kiwisaki)\
**Post date:** [January 29, 2024, 9:57am UTC](https://discuss.elastic.co/t/help-with-my-query/351975/1 "2024-01-29T09:57:51Z")

</div>

Can anyone advise where im going wrong with my query ?

I am trying to achieve the following:  
Generate an Alert whenever event.code 4648 is seen - with the only exception being to not alert if the winlog.event\_data.SubjectUserName matches the winlog.event\_data.TargetUsername field.

I have tried several variations of the following query, but i am still getting alerts whereby the Subject and Target user match for that windows event:

event.code:"4648" and (not winlog.event\_data.SubjectUserName:\* or not winlog.event\_data.TargetUserName:\* or not winlog.event\_data.SubjectUserName == winlog.event\_data.TargetUserName)

Appreciate any help, folks.

Thanks

---

<div class="post-metadata">

**Author:** ![yago82](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yago82/32/97755_2.png) [@yago82](https://discuss.elastic.co/u/yago82)\
**Post date:** [January 29, 2024, 3:32pm UTC](https://discuss.elastic.co/t/help-with-my-query/351975/2 "2024-01-29T15:32:33Z")

</div>

Hi,

The `not` operator is negating the entire condition, which is not what you want.

Try this:

```auto
event.code:"4648" AND NOT (winlog.event_data.SubjectUserName: * AND winlog.event_data.TargetUserName: * AND winlog.event_data.SubjectUserName == winlog.event_data.TargetUserName)

```

Regards

---

<div class="post-metadata">

**Author:** ![Kiwisaki](https://avatars.discourse-cdn.com/v4/letter/k/dfb087/32.png) [@Kiwisaki](https://discuss.elastic.co/u/Kiwisaki)\
**Post date:** [February 1, 2024, 1:46pm UTC](https://discuss.elastic.co/t/help-with-my-query/351975/3 "2024-02-01T13:46:28Z")

</div>

Hi yago82, thanks for your suggestion; i see what you mean.

Unfortunately im still having no luck with your suggested query ☹  
I have double and triple checked that ive got your query right, and also that the field values are the same in the activity that i want to exclude (subject and target user).

I may hav to explore other avenues of filtering this activity, annoyingly.

Really appreciate your help tho.

---

<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:** [February 29, 2024, 1:47pm UTC](https://discuss.elastic.co/t/help-with-my-query/351975/4 "2024-02-29T13:47:02Z")

</div>

Closed on February 29, 2024, 1:47pm UTC

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