# Diff query between two documents

**URL:** <https://discuss.elastic.co/t/diff-query-between-two-documents/156887>\
**Category:** Elasticsearch\
**Created:** [November 15, 2018, 2:28pm UTC](https://discuss.elastic.co/t/diff-query-between-two-documents/156887 "2018-11-15T14:28:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![elastic\_guy](https://avatars.discourse-cdn.com/v4/letter/e/ecb155/32.png) [@elastic\_guy](https://discuss.elastic.co/u/elastic_guy)\
**Post date:** [November 15, 2018, 2:28pm UTC](https://discuss.elastic.co/t/diff-query-between-two-documents/156887/1 "2018-11-15T14:28:49Z")

</div>

Hi,  
say I have a type that is modeled in the following way:

> document {  
> **id** : x,  
> **nested\_object** : [  
> {objects}, {objects}...  
> ] }

I am looking for a way to execute a diff query between two documents of this type, so that the diff will return all the inner nested objects that exist in one of the documents, but do not exist in the other one..

is it possible ?  
if so - do I have a way for controlling the equals function for comparing two nested documents?

---

<div class="post-metadata">

**Author:** ![Jaspreet\_Singh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jaspreet_singh/32/58296_2.png) [@Jaspreet\_Singh](https://discuss.elastic.co/u/Jaspreet_Singh)\
**Post date:** [November 16, 2018, 4:29pm UTC](https://discuss.elastic.co/t/diff-query-between-two-documents/156887/2 "2018-11-16T16:29:57Z")

</div>

Im not sure if you can `diff`, but the `exists` API will let you find out missing, null or empty objects in absolute terms. Take a look at [https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html)

---

<div class="post-metadata">

**Author:** ![elastic\_guy](https://avatars.discourse-cdn.com/v4/letter/e/ecb155/32.png) [@elastic\_guy](https://discuss.elastic.co/u/elastic_guy)\
**Post date:** [November 18, 2018, 1:16pm UTC](https://discuss.elastic.co/t/diff-query-between-two-documents/156887/3 "2018-11-18T13:16:42Z")

</div>

thanks for the comment, but this query is not suitable in my case.  
I need a more advance diff to find out nested objects that some of their field values are different..

---

<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:** [December 16, 2018, 1:16pm UTC](https://discuss.elastic.co/t/diff-query-between-two-documents/156887/4 "2018-12-16T13:16:43Z")

</div>

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