# Comparing two fields of the same document, where one of the fields is inside a nested document

**URL:** <https://discuss.elastic.co/t/comparing-two-fields-of-the-same-document-where-one-of-the-fields-is-inside-a-nested-document/21574>\
**Category:** Elasticsearch\
**Created:** [January 11, 2015, 5:17pm UTC](https://discuss.elastic.co/t/comparing-two-fields-of-the-same-document-where-one-of-the-fields-is-inside-a-nested-document/21574 "2015-01-11T17:17:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bart\_Kwasniewski](https://avatars.discourse-cdn.com/v4/letter/b/48db29/32.png) [@Bart\_Kwasniewski](https://discuss.elastic.co/u/Bart_Kwasniewski)\
**Post date:** [January 11, 2015, 5:17pm UTC](https://discuss.elastic.co/t/comparing-two-fields-of-the-same-document-where-one-of-the-fields-is-inside-a-nested-document/21574/1 "2015-01-11T17:17:47Z")

</div>

Consider the following document:

{  
"group" : "fans",  
"preferredFanId" : 1,  
"user" : [  
{  
"fanId" : 1,  
"first" : "John",  
"last" : "Smith"  
},  
{  
"fanId" : 2,  
"first" : "Alice",  
"last" : "White"  
},  
]  
}

where "user" is a nested document. I want to get inner\_hits (from  
2.0.0-SNAPSHOT) where preferredFanId == user.fanId , and so I want only the  
John Smith record returned in the inner\_hits. Is it possible? I've tried  
several approaches like using "include\_in\_parent" or "\_source", but nothing  
seems to work.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/40e4cd85-8c44-4eb2-94e7-0f059a8f7c4f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/40e4cd85-8c44-4eb2-94e7-0f059a8f7c4f%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 12:39am UTC](https://discuss.elastic.co/t/comparing-two-fields-of-the-same-document-where-one-of-the-fields-is-inside-a-nested-document/21574/2 "2017-07-06T00:39:42Z")

</div>


