# Interesting query: Documents where fields match and don't match

**URL:** <https://discuss.elastic.co/t/interesting-query-documents-where-fields-match-and-dont-match/91451>\
**Category:** Elasticsearch\
**Created:** [June 30, 2017, 2:33pm UTC](https://discuss.elastic.co/t/interesting-query-documents-where-fields-match-and-dont-match/91451 "2017-06-30T14:33:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jclose](https://avatars.discourse-cdn.com/v4/letter/j/df705f/32.png) [@jclose](https://discuss.elastic.co/u/jclose)\
**Post date:** [June 30, 2017, 2:33pm UTC](https://discuss.elastic.co/t/interesting-query-documents-where-fields-match-and-dont-match/91451/1 "2017-06-30T14:33:45Z")

</div>

I have an interesting query I'd like to run.

I'd like to find all documents where field field1 == field1, but field2 != field2.

So in layman's terms, maybe the negation is easier: don't show me documents where field1 always has the same field2 value (not that field1 matches field2, but that field2 never varies).

So for the example data set:

> ```
> User Login_Location
> jon US
> ben US
> ben Nigeria
> jon US
> sam UK
> jon US
> sam AU
> 
> ```

I want to get the documents for ben and sam, because they have Login\_Locations that have a variance.

Can anyone give me clues on how to accomplish this query?

---

<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 28, 2017, 2:34pm UTC](https://discuss.elastic.co/t/interesting-query-documents-where-fields-match-and-dont-match/91451/2 "2017-07-28T14:34:51Z")

</div>

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