# Kibana discover query where two fields are not the same?

**URL:** <https://discuss.elastic.co/t/kibana-discover-query-where-two-fields-are-not-the-same/321431>\
**Category:** Kibana\
**Tags:** kql-kibana-query-language\
**Created:** [December 16, 2022, 8:17pm UTC](https://discuss.elastic.co/t/kibana-discover-query-where-two-fields-are-not-the-same/321431 "2022-12-16T20:17:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![learningelastic](https://avatars.discourse-cdn.com/v4/letter/l/958977/32.png) [@learningelastic](https://discuss.elastic.co/u/learningelastic)\
**Post date:** [December 16, 2022, 8:17pm UTC](https://discuss.elastic.co/t/kibana-discover-query-where-two-fields-are-not-the-same/321431/1 "2022-12-16T20:17:53Z")

</div>

I tried running a query like `NOT client.geo.country_iso_code: source.geo.country_iso_code`, but it returned results where `client.geo.country_iso_code == source.geo.country_iso_code`

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/1/d/1df0f1be8c1718e729aab102d60f26720024c1a6.png)

Anyone know what's wrong with my query? I want results where `client.geo.country_iso_code != source.geo.country_iso_code`

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [December 16, 2022, 8:52pm UTC](https://discuss.elastic.co/t/kibana-discover-query-where-two-fields-are-not-the-same/321431/2 "2022-12-16T20:52:10Z")

</div>

Hi @learningelastic [KQL](https://www.elastic.co/guide/en/kibana/8.5/kuery-query.html#kuery-query) does not work like that ... it is using the right side as a literal .. it is not interpreting as a variable

so your query is actually this

`NOT client.geo.country_iso_code == 'client.geo.country_iso_code'`

return all documents where the the value of `client.geo.country_iso_code` is not equal to the literal `'client.geo.country_iso_code'` and since no documents have that value it is returning all the documents.

---

<div class="post-metadata">

**Author:** ![learningelastic](https://avatars.discourse-cdn.com/v4/letter/l/958977/32.png) [@learningelastic](https://discuss.elastic.co/u/learningelastic)\
**Post date:** [December 16, 2022, 9:04pm UTC](https://discuss.elastic.co/t/kibana-discover-query-where-two-fields-are-not-the-same/321431/3 "2022-12-16T21:04:25Z")

</div>

> [@stephenb](#):
>
> cuments have that v

Ooh ok that makes sense. Is it possible to treat the right side of the query as a variable or as a field?

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [December 16, 2022, 10:18pm UTC](https://discuss.elastic.co/t/kibana-discover-query-where-two-fields-are-not-the-same/321431/4 "2022-12-16T22:18:33Z")

</div>

Not today as far as I know.... You could open a feature request...

---

<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:** [January 13, 2023, 10:19pm UTC](https://discuss.elastic.co/t/kibana-discover-query-where-two-fields-are-not-the-same/321431/5 "2023-01-13T22:19:05Z")

</div>

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